QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#527515#8768. Arrested Developmenthnust_100teamWA 6ms42336kbC++14798b2024-08-22 16:23:242024-08-22 16:23:26

Judging History

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

  • [2024-08-22 16:23:26]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:42336kb
  • [2024-08-22 16:23:24]
  • 提交

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);
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		sum+=a;
		//cout<<"sum:"<<sum<<"\n";
		for(int j=sum;j>=a;j--){
			if(dp[j])dp[j]=min(dp[j-a],dp[j]+b);
			else dp[j]=dp[j-a];
			//if(dp[j])cout<<"j:"<<j<<" "<<dp[j]<<" "<<dp[j-a]<<"\n";
		}
		for(int j=a-1;j>=0;j--){
			if(dp[j])dp[j]+=b;
			//if(dp[j])cout<<"j:"<<j<<" "<<dp[j]<<"\n";
		}
		dp[sum-a]=b;
	}
	for(int i=0;i<=sum;i++){
		//if(dp[i])cout<<i<<" "<<dp[i]<<"\n";
		if(dp[i])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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 42272kb

input:

4
100 1
1 90
1 20
1 20

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 4ms
memory: 42244kb

input:

2
314 1
592 6

output:

7

result:

ok single line: '7'

Test #3:

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

input:

1
1 1

output:

1

result:

ok single line: '1'

Test #4:

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

input:

1
100000 1

output:

1

result:

ok single line: '1'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 42068kb

input:

1
1 100000

output:

100000

result:

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