제출 #1257981

#제출 시각아이디문제언어결과실행 시간메모리
1257981pinbu만두 (JOI14_ho_t2)C++20
100 / 100
9 ms560 KiB
#include <bits/stdc++.h> using namespace std; const int N = 10005, M = 505, MOD = 1e9 + 7; template<class T> void mini(T &X, T Y) {if (X > Y) X = Y;} template<class T> void maxi(T &X, T Y) {if (X < Y) X = Y;} int n, m, a[N]; int dp[N << 1]; signed main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n, greater<int>()); for (int i = 1; i <= n; i++) a[i] += a[i - 1]; dp[0] = 0; for (int i = 1; i <= n + 10000; i++) dp[i] = MOD; for (int j = 1, c, e; j <= m; j++) { cin >> c >> e; for (int i = n + 10000; i >= c; i--) { mini(dp[i], dp[i - c] + e); } } for (int i = n + 9999; i; i--) mini(dp[i], dp[i + 1]); int ans = 0; for (int i = 1; i <= n; i++) maxi(ans, a[i] - dp[i]); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...