QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#646215 | #3998. The Profiteer | Williamxzh | TL | 0ms | 4108kb | C++23 | 2.0kb | 2024-10-16 21:43:49 | 2024-10-16 21:43:50 |
Judging History
answer
#include <bits/stdc++.h>
#define il inline
using namespace std;
typedef long long ll;
il void cmax(int &x,int y){x=x>y?x:y;}
il int read(){
int x=0,c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
return x;
}
const int N=2e5+5;
int n,m,k,a[N],b[N],val[N];ll sum;
il void add(vector<int> &a,int v,int w){for(int i=k;i>=w;--i) cmax(a[i],a[i-w]+v);}
il int check(vector<int> a){
ll ret=0ll;
for(int i=0;i<=k;++i) ret+=1ll*a[i];
return ret<=1ll*m*k;
}
void solve(int l,int r,int s,int t,vector<int> cur){//cur:[1,l-1],[r+1,n]
if(l>r) return ;
int mid=(l+r)>>1,p=0,x,y,z,u,v,w,L,R,MID,ret=0;vector<int> c,X,d,c1,c2;
c=cur;
//for(int i=0;i<=k;++i) c[i]=0;
//for(int i=l;i<s;++i) add(c,val[i],a[i]);
for(int i=r;i>mid;--i) add(c,val[i],a[i]);
for(int i=mid;i>min(mid,t);--i) add(c,val[i],b[i]);
L=s,R=min(mid,t);
while(L<=R){
MID=(L+R)>>1,X=c;
for(int i=s;i<MID;++i) add(X,val[i],a[i]);
for(int i=MID;i<=min(mid,t);++i) add(X,val[i],b[i]);
/*if(MID==1){
printf("** %d : ",mid);
for(int i=1;i<=k;++i) printf("%d ",X[i]);puts("");
}*/
if(check(X)) ret=MID,L=MID+1;
else R=MID-1;
}
p=(ret?ret:s),sum+=1ll*ret;//printf("*** %d %d\n",mid,ret);
if(l==r) return ;
c=cur;for(int i=r;i>=mid;--i) add(c,val[i],a[i]);solve(l,mid-1,s,p,c);
c=cur;for(int i=s;i<p;++i) add(c,val[i],a[i]);solve(mid+1,r,p,t,c);
}
int x,y,z;ll u,v,w;vector<int> f;
int main(){
//freopen("ex_backpack3.in","r",stdin);
scanf("%d%d%d",&n,&k,&m);f.resize(k+1);for(int i=0;i<=k;++i) f[i]=0;
for(int i=1;i<=n;++i) val[i]=read(),a[i]=read(),b[i]=read();
for(int i=1;i<=n;++i) add(f,val[i],a[i]);
for(int i=1;i<=k;++i) w+=1ll*f[i];//printf("%d ",f[i]);puts("");
if(w<=1ll*m*k){printf("%lld",n*(n+1ll)/2ll);exit(0);}
for(int i=0;i<=k;++i) f[i]=0;
solve(1,n,1,n,f);
printf("%lld",sum);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3892kb
input:
4 5 3 3 2 4 1 2 3 2 1 2 3 1 3
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4108kb
input:
4 5 4 3 2 4 1 2 3 2 1 2 3 1 3
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4108kb
input:
4 5 5 3 2 4 1 2 3 2 1 2 3 1 3
output:
7
result:
ok single line: '7'
Test #4:
score: -100
Time Limit Exceeded
input:
200000 50 23333 2620 5 21 8192 17 34 6713 38 46 6687 13 42 390 9 13 4192 7 37 7898 17 21 1471 16 45 3579 22 40 9628 8 23 7164 28 45 3669 14 31 5549 29 35 4670 30 39 5811 15 20 4162 18 29 7590 29 41 7786 23 35 383 9 40 5576 39 46 5586 4 9 1110 14 33 8568 4 6 8548 39 42 9133 10 42 6679 22 39 8353 33 3...