QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526282#9167. Coprime Arrayhnust_xiaoqiWA 0ms29276kbC++20990b2024-08-21 12:55:552024-08-21 12:55:55

Judging History

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

  • [2024-08-21 12:55:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:29276kb
  • [2024-08-21 12:55:55]
  • 提交

answer

#include <bits/stdc++.h>
// #define int long long
#define endl "\n"

using namespace std;

const int N = 3e6 + 10, M = 60;

typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[N], b[N];
int dp[2][N];

void solve() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	memset(dp, 0x3f, sizeof dp);
	dp[0][0] = 0;
	
	int res = 1e8;
	int ma = 0;
	int now = 0, last = 1;
	for(int i = 1; i <= n; i++) {
		swap(now, last);
		for(int j = 0; j <= ma; j++) dp[now][j] = 1e8;
		for(int j = 0; j <= ma; j++) {
			if(dp[last][j] < 10000000) {
				dp[now][j] = min(dp[now][j], dp[last][j] + b[i]);
				dp[now][j + a[i]] = min(dp[now][j + a[i]], dp[last][j]);
				ma = max(ma, j + a[i]);
				ma = min(ma, N - 1);
			}
			if(i == n) res = min(res, max(j, dp[now][j]));
		}
	}
	cout << res << endl;
	
}

signed main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0);
	
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 29276kb

input:

9 6

output:

0

result:

wrong answer Sum of the elements is not equal to s