#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef int64_t ll;
//~ #define int ll
const int K = 7;
vector<ar<int, K>> dp[2][K];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, k, c; cin>>n>>k>>c;
dp[0][0].push_back({});
auto add = [&](auto& a, auto& b){
ar<int, K> res {};
for(int j=1;j<K;j++){
res[j] = max(a[j], b[j]);
res[0] += res[j];
} return res;
};
for(int i=1;i<=n;i++){
ar<int, K> a {};
for(int j=1;j<=k;j++){
cin>>a[j];
}
int t = i & 1, p = !t;
for(int j=0;j<=k;j++){
dp[t][j].clear();
dp[t][j].insert(dp[t][j].end(), dp[p][j].begin(), dp[p][j].end());
if(j){
for(auto x : dp[p][j - 1]){
dp[t][j].push_back(add(x, a));
}
sort(dp[t][j].begin(), dp[t][j].end(), [&](auto& a, auto& b){
return a[0] > b[0];
});
while((int)dp[t][j].size() > c * 5) dp[t][j].pop_back();
}
}
}
assert((int)dp[n & 1][k].size() >= c);
cout<<dp[n & 1][k][c - 1][0]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
1248 KB |
Output is correct |
2 |
Correct |
137 ms |
1240 KB |
Output is correct |
3 |
Correct |
119 ms |
1208 KB |
Output is correct |
4 |
Correct |
164 ms |
1124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
4788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1817 ms |
6504 KB |
Output is correct |
2 |
Correct |
1802 ms |
6524 KB |
Output is correct |
3 |
Incorrect |
1713 ms |
6668 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
1248 KB |
Output is correct |
2 |
Correct |
137 ms |
1240 KB |
Output is correct |
3 |
Correct |
119 ms |
1208 KB |
Output is correct |
4 |
Correct |
164 ms |
1124 KB |
Output is correct |
5 |
Incorrect |
67 ms |
4788 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |