Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- for(int ti = 1; ti <= t; ti++) {
- int s;
- cin >> s;
- ll arr[20000];
- for(int i = 0; i < s-1; i++) {
- cin >> arr[i];
- }
- ll mx = -1;
- ll mx_i = -1;
- ll mx_j = -2;
- ll sum = -5;
- ll curr_idx = -1;
- for(int i = 0; i < s-1; i++) {
- if(arr[i] > sum+arr[i]) {
- sum = arr[i];
- curr_idx = i;
- }
- else {
- sum += arr[i];
- }
- if(sum > mx || (sum == mx && i-curr_idx > mx_j-mx_i )) {
- mx = sum;
- mx_i = curr_idx;
- mx_j = i;
- }
- }
- if(mx == -1) {
- cout << "Route " << ti << " has no nice parts\n";
- }
- else {
- cout << "The nicest part of route " << ti << " is between stops " << mx_i+1 << " and " << mx_j+2 << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement