diff options
author | crupest <crupest@outlook.com> | 2021-03-23 19:11:22 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-03-23 19:11:22 +0800 |
commit | 250d5326031eb7c88f0cbc150c01e2e63f2479e6 (patch) | |
tree | 23a327683ae557fb04b8a0434dde590c53be9f4b | |
parent | 86accf12fc9f0e6b6a22b4b8e8dd0463593bec13 (diff) | |
download | crupest-250d5326031eb7c88f0cbc150c01e2e63f2479e6.tar.gz crupest-250d5326031eb7c88f0cbc150c01e2e63f2479e6.tar.bz2 crupest-250d5326031eb7c88f0cbc150c01e2e63f2479e6.zip |
import(solutions): Add 1240.
-rw-r--r-- | works/solutions/acwing/1240.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/works/solutions/acwing/1240.cpp b/works/solutions/acwing/1240.cpp new file mode 100644 index 0000000..8ebae33 --- /dev/null +++ b/works/solutions/acwing/1240.cpp @@ -0,0 +1,42 @@ +#include <iostream>
+
+int main() {
+ std::ios_base::sync_with_stdio(false);
+ std::cin.tie(nullptr);
+
+ int n;
+ std::cin >> n;
+
+ int current_count = 0;
+ int current_level_count = 1;
+ int current_level = 1;
+ long long current_sum = 0;
+ long long max_sum = -1000000;
+ int result = 1;
+
+ for (int i = 0; i < n; i++) {
+ long long a;
+ std::cin >> a;
+ current_sum += a;
+ current_count++;
+
+ if (current_count == current_level_count) {
+ if (current_sum > max_sum) {
+ max_sum = current_sum;
+ result = current_level;
+ }
+ current_count = 0;
+ current_level_count *= 2;
+ current_sum = 0;
+ current_level++;
+ }
+ }
+
+ if (current_count && current_sum > max_sum) {
+ result = current_level;
+ }
+
+ std::cout << result;
+
+ return 0;
+}
|