QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297301#3998. The ProfiteerrageOfThunderWA 252ms9988kbC++143.1kb2024-01-04 10:06:432024-01-04 10:06:44

Judging History

你现在查看的是最新测评结果

  • [2024-01-04 10:06:44]
  • 评测
  • 测评结果:WA
  • 用时:252ms
  • 内存:9988kb
  • [2024-01-04 10:06:43]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define int long long
#define mk make_pair
#define fi first
#define se second

using namespace std;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
	for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
	return x*f;
}

void cmax(ll &x,ll v){x=max(x,v);}

const int N=2e5+5;
const ll INF=1e11;
int n,k,a[N],b[N],c[N],E;
struct Knap{
	vector<ll>f;
	void init(){f.clear(),f.resize(k+1,0);}
	void ins(int x,int v){for(int i=k;i>=x;i--)cmax(f[i],f[i-x]+v);}
	bool valid(){
		// cout<<"check_valid f = ";for(int i=1;i<=k;i++)cout<<f[i]<<" ";puts("");
		ll res=0;for(int i=0;i<=k;i++)res+=f[i];return res<=1ll*k*E;
	}
};

int res[N];
Knap A;
void solve(int l,int r,int s,int t){
	// cout<<"solve "<<l<<" "<<r<<" "<<s<<" "<<t<<endl;
	if(l>r)return ;
	if(s==t){for(int i=l;i<=r;i++)res[i]=s;return ;}
	Knap B=A;
	int p=(l+r)>>1,L=max(s,p),R=t,ans=t+1;
	// cout<<"p = "<<p<<endl;
	for(int i=l;i<p;i++)B.ins(a[i],c[i]);
	for(int i=p;i<=min(r,s-1);i++)B.ins(b[i],c[i]);
	// for(int i=l;i<p;i++)cout<<"ins1 "<<i<<endl;
	// for(int i=p;i<=min(r,s-1);i++)cout<<"ins2 "<<i<<endl;
	while(L<=R){
		int mid=(L+R)>>1;
		// cout<<"check mid = "<<mid<<endl;
		auto C=B;
		// for(int i=mid+1;i<=R;i++)cout<<"try ins1 "<<i<<endl;
		// for(int i=max(L,p);i<=mid;i++)cout<<"try ins2 "<<i<<endl;
		for(int i=mid+1;i<=R;i++)C.ins(a[i],c[i]);
		for(int i=max(L,p);i<=mid;i++)C.ins(b[i],c[i]);
		if(C.valid()){
			// puts("valid");
			// for(int i=mid;i<=R;i++)cout<<"ins1 "<<i<<endl;
			for(int i=mid;i<=R;i++)B.ins(a[i],c[i]);
			ans=mid,R=mid-1;
		}
		else{
			// puts("invalid");
			// for(int i=max(L,p);i<=mid;i++)cout<<"ins2 "<<i<<endl;
			for(int i=max(L,p);i<=mid;i++)B.ins(b[i],c[i]);
			L=mid+1;
		}
	}
	res[p]=ans;
	// cout<<"res "<<p<<" = "<<ans<<endl;
	
	B=A;
	// for(int i=ans+1;i<=t;i++)cout<<"all -> ins1 "<<i<<endl;
	// for(int i=p;i<=min(r,s-1);i++)cout<<"all -> ins2 "<<i<<endl;
	for(int i=min(ans,t)+1;i<=t;i++)A.ins(a[i],c[i]);
	for(int i=p;i<=min(r,s-1);i++)A.ins(b[i],c[i]);
	solve(l,p-1,s,min(ans,t));
	
	// A=B;for(int i=l;i<=p;i++)cout<<"all -> ins1 "<<i<<endl;
	// for(int i=max(r+1,s);i<=ans;i++)cout<<"all -> ins2 "<<i<<endl;
	for(int i=l;i<=p;i++)A.ins(a[i],c[i]);
	for(int i=max(r+1,s);i<max(ans,s);i++)A.ins(b[i],c[i]);
	solve(p+1,r,max(ans,s),t);
}

signed main(void){

#ifndef ONLINE_JUDGE
	freopen("q.in","r",stdin);
#endif

	n=read(),k=read(),E=read();
	for(int i=1;i<=n;i++)c[i]=read(),a[i]=read(),b[i]=read();

	int L=1,R=n,p=0;
	A.init();
	while(L<=R){
		int mid=(L+R)>>1;
		// cout<<"mid = "<<mid<<endl;
		auto B=A;
		for(int i=L;i<mid;i++)B.ins(a[i],c[i]);
		for(int i=mid;i<=R;i++)B.ins(b[i],c[i]);
		if(B.valid()){
			for(int i=L;i<=mid;i++)A.ins(a[i],c[i]);
			L=mid+1,p=mid;
		}
		else{
			for(int i=mid;i<=R;i++)A.ins(b[i],c[i]);
			R=mid-1;
		}
	}
	// cout<<"p = "<<p<<endl;
	for(int i=p+1;i<=n;i++)res[i]=n+1;

	A.init();
	solve(1,p,1,n);

	ll ans=0;
	for(int i=1;i<=n;i++)ans+=n-res[i]+1;
	cout<<ans<<endl;

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7684kb

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: 7680kb

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: 1ms
memory: 7588kb

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: 0
Accepted
time: 19ms
memory: 9808kb

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...

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 252ms
memory: 9988kb

input:

200000 50 233332
8019 18 20
3111 27 40
2015 16 47
6491 17 18
1224 30 38
428 23 34
7521 4 41
7252 6 33
4121 32 45
4230 18 35
1605 21 42
9489 17 25
3704 35 45
6202 8 22
6493 1 5
3041 14 46
4509 23 43
9646 11 48
5294 19 27
3562 19 40
9408 30 47
1751 21 29
4053 4 27
5596 32 49
8609 13 29
1686 4 31
3588 ...

output:

12149901

result:

wrong answer 1st lines differ - expected: '17523021', found: '12149901'