Submission #1247867

#TimeUsernameProblemLanguageResultExecution timeMemory
1247867tvgk만두 (JOI14_ho_t2)C++20
100 / 100
15 ms328 KiB
#include<bits/stdc++.h> using namespace std; #define task "a" #define se second #define fi first #define ll long long #define ii pair<int, int> const long mxN = 1e4 + 7, inf = 1e9 + 7; int n, m, a[mxN], dp[mxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(task".INP", "r", stdin); //freopen(task".OUT", "w", stdout); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = inf; } sort(a + 1, a + n + 1, greater<int>()); for (int i = 1; i <= m; i++) { ii b; cin >> b.fi >> b.se; for (int j = n; j >= 0; j--) dp[min(n, j + b.fi)] = min(dp[min(n, j + b.fi)], dp[j] + b.se); for (int j = n; j > 0; j--) dp[j - 1] = min(dp[j - 1], dp[j]); } int pre = 0, ans = 0; for (int i = 0; i <= n; i++) { pre += a[i]; ans = max(ans, pre - dp[i]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...