Submission #486386

#TimeUsernameProblemLanguageResultExecution timeMemory
486386KienTranFeast (NOI19_feast)C++14
59 / 100
136 ms262148 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int O = 3e5 + 5; int n, k, a[O]; vector <vector <int>> f[2]; main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++ i) cin >> a[i]; for (int i = 0; i < 2; ++ i){ f[i].resize(n + 1); for (int j = 0; j <= n; ++ j) f[i][j].resize(k + 1); } for (int i = 1; i <= n; ++ i){ for (int j = 1; j <= k; ++ j){ f[0][i][j] = max(f[1][i - 1][j - 1], f[0][i - 1][j]) + a[i]; f[1][i][j] = max({f[0][i][j], f[1][i - 1][j - 1], f[1][i - 1][j]}); } } cout << f[1][n][k]; }

Compilation message (stderr)

feast.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...