# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
237722 | 2020-06-08T12:43:02 Z | Half | Feast (NOI19_feast) | C++14 | 1000 ms | 4204 KB |
#include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmath> using namespace std; typedef vector<int> vi; typedef pair<int,int> pi; typedef long long ll; #define loop(i,a,b) for (int i = a; i <= b; i++) #define INF ((unsigned) ~0) #define F first #define S second #define PB push_back #define MP make_pair const int MXN = 500000; int N, K; int a[MXN]; vi g; vector<ll> sg; //ll mem[4000][4000]; int main(){ cin >> N >> K; for(int i = 0; i < N; i++){ cin >> a[i]; if(g.size() == 0){ g.push_back(a[i]); }else if((g[g.size() - 1] >= 0 && a[i] >= 0) || (g[g.size() - 1] < 0 && a[i] < 0)){ g[g.size() - 1] += a[i]; }else{ //cout << g[g.size() - 1] << " "; g.push_back(a[i]); } } //cout << "\n"; /*for(int i = 0; i < 4000; i++) for(int j = 0; j < 4000; j++) mem[i][j] = -1;*/ ll sm = 0; sg.push_back(0); for(int i = 0; i < g.size(); i++){ sm += g[i]; sg.push_back(sm); } if(g.size() == 1){ cout << g[0] << "\n"; }else if(g.size() == 2){ cout << max(g[0], g[1]) << "\n"; }else if(g.size() == 3 && g[0] > 0){ if(K == 1) cout << max(max(g[0], g[2]), g[0] + g[1] + g[2]) << "\n"; if(K >= 2) cout << g[0] + g[2] << "\n"; }else if(K == 1){ ll mx = 0; for(int i = 0; i < g.size(); i++) for(int j = i + 1; j < g.size() + 1; j++) mx = max(mx, sg[j] - sg[i]); cout << mx << "\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 175 ms | 2292 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 94 ms | 1528 KB | Output is correct |
2 | Correct | 95 ms | 1528 KB | Output is correct |
3 | Correct | 93 ms | 1400 KB | Output is correct |
4 | Correct | 95 ms | 1400 KB | Output is correct |
5 | Execution timed out | 1087 ms | 2548 KB | Time limit exceeded |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1093 ms | 4204 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 175 ms | 2292 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |