QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#526254 | #9167. Coprime Array | hnust_xiaoqi | ML | 0ms | 0kb | C++20 | 886b | 2024-08-21 12:43:32 | 2024-08-21 12:43:32 |
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 = 1e18;
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 - 5);
}
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
9 6
output:
0