Submission #448251

#TimeUsernameProblemLanguageResultExecution timeMemory
448251JovanB만두 (JOI14_ho_t2)C++17
100 / 100
16 ms492 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int INF = 1e9; int dp[20005]; int a[10005]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; for(int i=1; i<=n; i++){ cin >> a[i]; } sort(a+1, a+1+n); reverse(a+1, a+1+n); for(int i=1; i<=2e4; i++) dp[i] = INF; for(int i=1; i<=m; i++){ int x, y; cin >> x >> y; for(int j=2e4; j>=x; j--){ dp[j] = min(dp[j], y + dp[j-x]); } } for(int j=2e4-1; j>=1; j--){ dp[j] = min(dp[j], dp[j+1]); } int res = 0; int sum = 0; for(int i=1; i<=n; i++){ sum += a[i]; res = max(res, sum - dp[i]); } cout << res << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...