/* 2026
* Maciej Szeptuch
*/
#include <algorithm>
#include <cstdio>
const int MAX_PANCAKES = 524288;
int stacks;
int size;
int limit;
long long pancake[MAX_PANCAKES];
long long result[MAX_PANCAKES];
int main(void)
{
scanf("%d %d %d", &stacks, &size, &limit);
for(int s = 0; s < stacks; ++s)
{
for(int p = 0; p < size; ++p)
{
scanf("%lld", &pancake[p]);
if(p)
pancake[p] += pancake[p - 1];
}
for(int c = std::min((s + 1) * size, limit); c >= 0; --c)
{
for(int p = 0; p < size && p < c; ++p)
result[c] = std::max(
result[c],
result[c - p - 1] + pancake[p]);
}
}
printf("%lld\n", result[limit]);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* 2026 * Maciej Szeptuch */ #include <algorithm> #include <cstdio> const int MAX_PANCAKES = 524288; int stacks; int size; int limit; long long pancake[MAX_PANCAKES]; long long result[MAX_PANCAKES]; int main(void) { scanf("%d %d %d", &stacks, &size, &limit); for(int s = 0; s < stacks; ++s) { for(int p = 0; p < size; ++p) { scanf("%lld", &pancake[p]); if(p) pancake[p] += pancake[p - 1]; } for(int c = std::min((s + 1) * size, limit); c >= 0; --c) { for(int p = 0; p < size && p < c; ++p) result[c] = std::max( result[c], result[c - p - 1] + pancake[p]); } } printf("%lld\n", result[limit]); return 0; } |
English