URAL-1998 The old Padawan 二分

时间:2021-09-07 21:30:41

  题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1998

  题意:有n个石头,每个石头有个重量,每个时间点你能让一个石头飞起来,但有m个时间点,你会分心,使得已经飞起来的石头会有重量之和大于k的石头掉下来,问你最终使的所有石头飞起来的时间。

  维护一个前缀和,然后二分就可以了。

 //STATUS:C++_AC_93MS_1113KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int t[N],sum[N];
int n,m,k; int binary(int l,int r,LL tar)
{
int mid;
while(l<r){
mid=(l+r)>>;
if(sum[mid]<tar)l=mid+;
else r=mid;
}
return l;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,a,w,ans;
while(~scanf("%d%d%d",&n,&m,&k))
{
for(i=;i<=n;i++){
scanf("%d",&a);
sum[i]=sum[i-]+a;
}
for(i=;i<=m;i++)
scanf("%d",&t[i]);
w=ans=;
for(i=;i<=m;i++){
w+=t[i]-t[i-]-;
if(w>=n){
ans+=n-(w-(t[i]-t[i-]-));
break;
}
ans=t[i];
w=binary(,w+,sum[w]-k)-;
}
if(w<n){
ans+=n-w;
} printf("%d\n",ans);
}
return ;
}