#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
#define mup(x,y) x = min(x,y)
#define Mup(x,y) x = max(x,y)
using namespace std;
using ll = long long;
const int M = 10003, N = 503;
int m, n;
int p[M];
int c[N], e[N];
ll dp[M+M], sfx[M+M];
int main() {
scanf("%d%d", &m, &n);
rep(i,1,m) scanf("%d", &p[i]);
sort(p+1,p+m+1,greater<>());
rep(i,1,n) scanf("%d%d", &c[i], &e[i]);
fill(dp,dp+M+M,1e18);
fill(sfx,sfx+M+M,1e18);
dp[0] = 0;
int mx = *max_element(p+1,p+m+1);
rep(j,1,n) per(i,0,m+M) {
if (i >= c[j])
mup(dp[i],dp[i-c[j]]+e[j]);
}
ll ans = 0, pfx = 0;
per(i,0,m+M) sfx[i] = min(sfx[i-1],dp[i]);
rep(i,0,m+M) {
if (i <= m) pfx += p[i];
Mup(ans, pfx - sfx[i]);
}
printf("%lld", ans);
}
Compilation message
2014_ho_t2.cpp: In function 'int main()':
2014_ho_t2.cpp:23:9: warning: unused variable 'mx' [-Wunused-variable]
23 | int mx = *max_element(p+1,p+m+1);
| ^~
2014_ho_t2.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d%d", &m, &n);
| ~~~~~^~~~~~~~~~~~~~~~
2014_ho_t2.cpp:17:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | rep(i,1,m) scanf("%d", &p[i]);
| ~~~~~^~~~~~~~~~~~~
2014_ho_t2.cpp:19:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | rep(i,1,n) scanf("%d%d", &c[i], &e[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
708 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
604 KB |
Output is correct |
2 |
Correct |
10 ms |
852 KB |
Output is correct |
3 |
Correct |
17 ms |
836 KB |
Output is correct |
4 |
Correct |
11 ms |
824 KB |
Output is correct |
5 |
Correct |
13 ms |
604 KB |
Output is correct |
6 |
Correct |
6 ms |
604 KB |
Output is correct |
7 |
Correct |
9 ms |
824 KB |
Output is correct |
8 |
Correct |
10 ms |
604 KB |
Output is correct |
9 |
Correct |
6 ms |
768 KB |
Output is correct |
10 |
Correct |
10 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
708 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
11 ms |
604 KB |
Output is correct |
12 |
Correct |
10 ms |
852 KB |
Output is correct |
13 |
Correct |
17 ms |
836 KB |
Output is correct |
14 |
Correct |
11 ms |
824 KB |
Output is correct |
15 |
Correct |
13 ms |
604 KB |
Output is correct |
16 |
Correct |
6 ms |
604 KB |
Output is correct |
17 |
Correct |
9 ms |
824 KB |
Output is correct |
18 |
Correct |
10 ms |
604 KB |
Output is correct |
19 |
Correct |
6 ms |
768 KB |
Output is correct |
20 |
Correct |
10 ms |
604 KB |
Output is correct |
21 |
Correct |
10 ms |
856 KB |
Output is correct |
22 |
Correct |
10 ms |
604 KB |
Output is correct |
23 |
Correct |
10 ms |
860 KB |
Output is correct |
24 |
Correct |
10 ms |
860 KB |
Output is correct |
25 |
Correct |
10 ms |
852 KB |
Output is correct |
26 |
Correct |
10 ms |
604 KB |
Output is correct |
27 |
Correct |
6 ms |
600 KB |
Output is correct |
28 |
Correct |
10 ms |
832 KB |
Output is correct |
29 |
Correct |
13 ms |
768 KB |
Output is correct |
30 |
Correct |
11 ms |
604 KB |
Output is correct |