QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526261#9167. Coprime Arrayhnust_xiaoqiML 0ms0kbC++20888b2024-08-21 12:46:462024-08-21 12:46:47

Judging History

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

  • [2024-08-21 12:46:47]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-08-21 12:46:46]
  • 提交

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[M][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;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= ma; j++) {
			if(dp[i - 1][j] < 10000000) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + b[i]);
				dp[i][j + a[i]] = min(dp[i][j + a[i]], dp[i - 1][j]);
				ma = max(ma, j + a[i]);
				ma = min(ma, N - 1);
			}
			if(i == n) res = min(res, max(j, dp[i][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();
	}
}

详细

Test #1:

score: 0
Memory Limit Exceeded

input:

9 6

output:

0

result: