| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1307062 | nanaseyuzuki | 만두 팔기 (JOI14_manju) | C++20 | 18 ms | 4516 KiB |
#include <bits/stdc++.h>
// Kazusa_Megumi
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e18;
int m, n, p[mn], dp[mn];
void solve() {
cin >> m >> n;
for(int i = 1; i <= m; i++) cin >> p[i];
sort(p + 1, p + m + 1, greater <int> ());
fill(dp, dp + mn, inf);
dp[0] = 0;
for(int i = 1; i <= n; i++){
int e, c; cin >> c >> e;
for(int i = m; i >= 0; i--) dp[min(m, i + c)] = min(dp[min(m, i + c)], dp[i] + e);
for(int i = m; i >= 0; i--) dp[i - 1] = min(dp[i], dp[i - 1]);
}
int ans = 0, cur = 0;
for(int i = 1; i <= m; i++){
cur += p[i], ans = max(ans, cur - dp[i]);
}
cout << ans << '\n';
}
main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
if (fopen("Kazuki.INP", "r")) {
freopen("Kazuki.INP", "r", stdin);
freopen("Kazuki.OUT", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
