Submission #1042124
Source Code Expand
/// In the name of God #include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int,int> pii; typedef long long ll; typedef long double ld; typedef vector<int> vi; #define X first #define Y second #define all(o) o.begin(), o.end() #define IOS ios::sync_with_stdio(0), cin.tie(0) pii gg(vi v){ sort(all(v), greater<int>()); int sum = 0, cnt = 0; for(int i=0; i<v.size(); i++){ if(v[i] >= 0){ sum += v[i]; cnt++; } } int ans[2]; ans[cnt % 2] = sum; int oth = 1 ^ (cnt % 2); if(cnt == v.size()) ans[oth] = sum - v[cnt - 1]; else{ if(cnt - 1 >= 0) ans[oth] = max(sum + v[cnt], sum - v[cnt - 1]); else ans[oth] = sum + v[cnt]; } return {ans[0], ans[1]}; } const int maxn = 2e5 + 10; vi adj[maxn]; main(){ int n, k; cin >> n >> k; for(int i=0; i<n; i++){ int x; cin >> x; adj[i % k].push_back(x); } int ev = 0, od = 0; for(int i=0; i<k; i++){ pii res = gg(adj[i]); ev += res.X, od += res.Y; cout << res.X << " " << res.Y << endl; } cout << max(od, ev) << endl; }
Submission Info
Submission Time | |
---|---|
Task | B - Contiguous Repainting |
User | sasa99 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1219 Byte |
Status | WA |
Exec Time | 536 ms |
Memory | 9216 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | WA | 7 ms | 4864 KB |
0_01.txt | WA | 7 ms | 4864 KB |
0_02.txt | WA | 7 ms | 4992 KB |
0_03.txt | WA | 7 ms | 4864 KB |
1_00.txt | WA | 7 ms | 4864 KB |
1_01.txt | WA | 7 ms | 4864 KB |
1_02.txt | WA | 7 ms | 4992 KB |
1_03.txt | WA | 29 ms | 6644 KB |
1_04.txt | WA | 83 ms | 6644 KB |
1_05.txt | WA | 81 ms | 6644 KB |
1_06.txt | WA | 82 ms | 6644 KB |
1_07.txt | WA | 81 ms | 6644 KB |
1_08.txt | WA | 536 ms | 9216 KB |
1_09.txt | WA | 525 ms | 9216 KB |
1_10.txt | WA | 514 ms | 9088 KB |
1_11.txt | WA | 376 ms | 7936 KB |
1_12.txt | WA | 351 ms | 7552 KB |
1_13.txt | WA | 385 ms | 8064 KB |
1_14.txt | WA | 504 ms | 9088 KB |
1_15.txt | WA | 315 ms | 7168 KB |
1_16.txt | WA | 242 ms | 7168 KB |
1_17.txt | WA | 199 ms | 7040 KB |
1_18.txt | WA | 383 ms | 7936 KB |
1_19.txt | WA | 449 ms | 8576 KB |
1_20.txt | WA | 396 ms | 8192 KB |
1_21.txt | WA | 463 ms | 8832 KB |