# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930358 |
2024-02-19T12:51:46 Z |
vjudge1 |
Feast (NOI19_feast) |
C++17 |
|
23 ms |
32088 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
template<typename T>
inline bool maxi(T &x, const T &val)
{
if (x < val) return x = val, true;
return false;
}
template<typename T>
inline bool mini(T &x, const T &val)
{
if (x > val) return x = val, true;
return false;
}
const int maxn = 2010;
int n, k;
int a[maxn], S[maxn];
int dp[maxn][maxn];
void solve()
{
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i], S[i] = S[i - 1] + a[i];
for (int i = 1; i <= n; i++) {
int cur = 0;
for (int j = 1; j <= n; j++) {
maxi(dp[i][j], dp[i][j - 1]);
maxi(dp[i][j], dp[i - 1][j]);
maxi(dp[i][j], cur + S[j]);
maxi(cur, dp[i - 1][j] - S[j]);
}
}
cout << dp[k][n] << '\n';
}
signed main()
{
#ifdef LOCAL
clock_t st = clock();
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
#define Task ""
#ifdef LOCAL
if (!fopen("D:\\.inp", "r")) {
freopen("D:\\.inp", "w", stdout);
freopen("D:\\.out", "w", stdout);
cerr << "get input from file\n";
return 0;
}
freopen("D:\\.inp", "r", stdin);
freopen("D:\\.out", "w", stdout);
#else
if (fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
#endif
solve();
#ifdef LOCAL
cerr << clock() - st << endl;
#endif
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(Task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(Task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
2140 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
1 ms |
2140 KB |
Output is correct |
15 |
Correct |
1 ms |
2136 KB |
Output is correct |
16 |
Correct |
1 ms |
1884 KB |
Output is correct |
17 |
Correct |
1 ms |
2140 KB |
Output is correct |
18 |
Correct |
1 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1884 KB |
Output is correct |
20 |
Correct |
1 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
2140 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
1 ms |
2140 KB |
Output is correct |
15 |
Correct |
1 ms |
2136 KB |
Output is correct |
16 |
Correct |
1 ms |
1884 KB |
Output is correct |
17 |
Correct |
1 ms |
2140 KB |
Output is correct |
18 |
Correct |
1 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1884 KB |
Output is correct |
20 |
Correct |
1 ms |
2140 KB |
Output is correct |
21 |
Correct |
20 ms |
31068 KB |
Output is correct |
22 |
Correct |
20 ms |
30720 KB |
Output is correct |
23 |
Correct |
20 ms |
31068 KB |
Output is correct |
24 |
Correct |
22 ms |
30920 KB |
Output is correct |
25 |
Correct |
22 ms |
31836 KB |
Output is correct |
26 |
Correct |
21 ms |
32088 KB |
Output is correct |
27 |
Correct |
23 ms |
31856 KB |
Output is correct |
28 |
Correct |
22 ms |
31572 KB |
Output is correct |
29 |
Correct |
21 ms |
31320 KB |
Output is correct |
30 |
Correct |
20 ms |
30976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |