QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#526261 | #9167. Coprime Array | hnust_xiaoqi | ML | 0ms | 0kb | C++20 | 888b | 2024-08-21 12:46:46 | 2024-08-21 12:46:47 |
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