Submission #2408928
Source Code Expand
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); vector<long long> a(N); long long sum_a = 0; long long sum_b = 0; for (int i = 0; i < N; i++) { scanf("%lld", &a[i]); if (i % 2 == 0 && a[i] >= 0) sum_a += a[i]; if (i % 2 != 0 && a[i] >= 0) sum_b += a[i]; } vector<int> cnt; if (sum_a == 0 && sum_b == 0){ long long max = a[0]; int idx = 0; for (int i = 1; i < N; i++) { if (max < a[i]) { max = a[i]; idx = i; } } printf("%lld\n", max); printf("%d\n", N-1); for (int i = N-1; i > idx; i--) printf("%d\n", i+1); for (int i = 0; i < idx; i++) printf("%d\n", 1); } else { if (sum_a < sum_b) { a.erase(a.begin()); cnt.push_back(1); } while (a.size() > 3) { if (a[0] < 0) { a.erase(a.begin()); cnt.push_back(1); a.erase(a.begin()); cnt.push_back(1); } else { if (a[2] >= 0) { a.erase(a.begin(), a.begin()+2); cnt.push_back(2); } else { a.erase(a.begin()+1, a.begin()+3); cnt.push_back(3); } } } if (a.size() == 3) { if (a[0] < 0) { cnt.push_back(1); cnt.push_back(1); } else { if (a[2] < 0) { cnt.push_back(3); cnt.push_back(2); } else { cnt.push_back(2); } } } else if (a.size() == 2) { cnt.push_back(2); } printf("%lld\n", max(sum_a, sum_b)); printf("%d\n", cnt.size()); for (int i = 0; i < cnt.size(); i++){ printf("%d\n", cnt[i]); } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Both Sides Merger |
User | atumari |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2089 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:68:34: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>::size_type {aka long unsigned int}’ [-Wformat=] printf("%d\n", cnt.size()); ^ ./Main.cpp:6:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.cpp:12:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld", &a[i]); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_0, example_1, example_2, example_3 |
All | allneg_0, allneg_1, allneg_2, bigans_0, bigans_1, bigans_2, bigans_3, bigans_4, bigans_5, bigans_6, bigans_7, bigans_8, bigans_9, example_0, example_1, example_2, example_3, maxrand_0, maxrand_1, maxrand_10, maxrand_11, maxrand_12, maxrand_13, maxrand_14, maxrand_15, maxrand_16, maxrand_17, maxrand_18, maxrand_19, maxrand_2, maxrand_20, maxrand_21, maxrand_22, maxrand_23, maxrand_24, maxrand_25, maxrand_26, maxrand_27, maxrand_28, maxrand_29, maxrand_3, maxrand_4, maxrand_5, maxrand_6, maxrand_7, maxrand_8, maxrand_9, rand_0, rand_1, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
allneg_0 | AC | 1 ms | 256 KB |
allneg_1 | AC | 1 ms | 256 KB |
allneg_2 | AC | 1 ms | 256 KB |
bigans_0 | AC | 1 ms | 256 KB |
bigans_1 | AC | 1 ms | 256 KB |
bigans_2 | AC | 1 ms | 256 KB |
bigans_3 | AC | 1 ms | 256 KB |
bigans_4 | AC | 1 ms | 256 KB |
bigans_5 | AC | 1 ms | 256 KB |
bigans_6 | AC | 1 ms | 256 KB |
bigans_7 | AC | 1 ms | 256 KB |
bigans_8 | AC | 1 ms | 256 KB |
bigans_9 | AC | 1 ms | 256 KB |
example_0 | AC | 1 ms | 256 KB |
example_1 | AC | 1 ms | 256 KB |
example_2 | AC | 1 ms | 256 KB |
example_3 | AC | 1 ms | 256 KB |
maxrand_0 | AC | 1 ms | 256 KB |
maxrand_1 | AC | 1 ms | 256 KB |
maxrand_10 | AC | 1 ms | 256 KB |
maxrand_11 | AC | 1 ms | 256 KB |
maxrand_12 | AC | 1 ms | 256 KB |
maxrand_13 | AC | 1 ms | 256 KB |
maxrand_14 | AC | 1 ms | 256 KB |
maxrand_15 | AC | 1 ms | 256 KB |
maxrand_16 | AC | 1 ms | 256 KB |
maxrand_17 | AC | 1 ms | 256 KB |
maxrand_18 | AC | 1 ms | 256 KB |
maxrand_19 | AC | 1 ms | 256 KB |
maxrand_2 | AC | 1 ms | 256 KB |
maxrand_20 | AC | 1 ms | 256 KB |
maxrand_21 | AC | 1 ms | 256 KB |
maxrand_22 | AC | 1 ms | 256 KB |
maxrand_23 | AC | 1 ms | 256 KB |
maxrand_24 | AC | 1 ms | 256 KB |
maxrand_25 | AC | 1 ms | 256 KB |
maxrand_26 | AC | 1 ms | 256 KB |
maxrand_27 | AC | 1 ms | 256 KB |
maxrand_28 | AC | 1 ms | 256 KB |
maxrand_29 | AC | 1 ms | 256 KB |
maxrand_3 | AC | 1 ms | 256 KB |
maxrand_4 | AC | 1 ms | 256 KB |
maxrand_5 | AC | 1 ms | 256 KB |
maxrand_6 | AC | 1 ms | 256 KB |
maxrand_7 | AC | 1 ms | 256 KB |
maxrand_8 | AC | 1 ms | 256 KB |
maxrand_9 | AC | 1 ms | 256 KB |
rand_0 | AC | 1 ms | 256 KB |
rand_1 | AC | 1 ms | 256 KB |
rand_2 | AC | 1 ms | 256 KB |
rand_3 | AC | 1 ms | 256 KB |
rand_4 | AC | 1 ms | 256 KB |
rand_5 | AC | 1 ms | 256 KB |
rand_6 | AC | 1 ms | 256 KB |
rand_7 | AC | 1 ms | 256 KB |
rand_8 | AC | 1 ms | 256 KB |
rand_9 | AC | 1 ms | 256 KB |