이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |