QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#527828#8768. Arrested Developmenthnust_100teamWA 46ms42336kbC++141.0kb2024-08-22 19:59:502024-08-22 19:59:50

Judging History

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

  • [2024-08-22 19:59:50]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:42336kb
  • [2024-08-22 19:59:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long int
void solve(){
	int n,a,b,sum=0,ans=1e9;
	cin>>n;
	vector<int>dp(5000100,-1);
	dp[0]=0;
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		sum+=a;
		//cout<<"sum:"<<sum<<"\n";
		dp[sum]=0;
		for(int j=sum-1;j>=max(sum-a+1,a);j--){//之前不可能出现 
			dp[j]=dp[j-a];
			//cout<<"j:"<<j<<" "<<dp[j]<<" "<<dp[j-a]<<"\n";
		}
		for(int j=sum-a;j>=a;j--){
			if(dp[j]>=0)dp[j]=min(dp[j-a],dp[j]+b);//搭配过 
			else dp[j]=dp[j-a];//未搭配过
			//cout<<"j:"<<j<<" "<<dp[j]<<"\n";
		}
		for(int j=min(a-1,sum-a);j>=0;j--){//不能被别的组合得出 
			if(dp[j]>=0)dp[j]+=b;
			//cout<<"j:"<<j<<" "<<dp[j]<<"\n";
		}
		//if(dp[sum-a]==0)dp[sum-a]=b;
	}
	for(int i=0;i<=sum;i++){
		//if(dp[i]>=0)cout<<i<<" "<<dp[i]<<"\n";
		if(dp[i]>=0)ans=min(ans,max(i,dp[i]));
	}
	cout<<ans<<"\n";
	return;
}
signed main(){
	//ios::sync_with_stdio(0);
	//cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 42280kb

input:

4
100 1
1 90
1 20
1 20

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 42256kb

input:

2
314 1
592 6

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 3ms
memory: 42124kb

input:

1
1 1

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 42268kb

input:

1
100000 1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 3ms
memory: 42336kb

input:

1
1 100000

output:

1

result:

ok single line: '1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 42296kb

input:

1
100000 100000

output:

100000

result:

ok single line: '100000'

Test #7:

score: -100
Wrong Answer
time: 46ms
memory: 42332kb

input:

50
78681 95291
22639 1538
12119 52253
50430 63757
66133 92826
61048 40069
33506 30382
96049 50134
42895 62735
86943 16955
9667 61843
49647 9320
29082 16909
69601 68436
19892 34306
29822 79462
73262 14568
1693 35040
89757 61888
56993 48750
89611 77773
54159 21067
32520 41091
52501 92770
36530 17589
5...

output:

1135563

result:

wrong answer 1st lines differ - expected: '855897', found: '1135563'