Advertisement
_rashed

UVA 507

Jul 14th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. int main()
  9. {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(NULL);
  12.     cout.tie(NULL);
  13.     int t;
  14.     cin >> t;
  15.     for(int ti = 1; ti <= t; ti++) {
  16.         int s;
  17.         cin >> s;
  18.         ll arr[20000];
  19.         for(int i = 0; i < s-1; i++) {
  20.             cin >> arr[i];
  21.         }
  22.         ll mx = -1;
  23.         ll mx_i = -1;
  24.         ll mx_j = -2;
  25.         ll sum = -5;
  26.         ll curr_idx = -1;
  27.         for(int i = 0; i < s-1; i++) {
  28.             if(arr[i] > sum+arr[i]) {
  29.                 sum = arr[i];
  30.                 curr_idx = i;
  31.             }
  32.             else {
  33.                 sum += arr[i];
  34.             }
  35.             if(sum > mx || (sum == mx && i-curr_idx > mx_j-mx_i )) {
  36.                 mx = sum;
  37.                 mx_i = curr_idx;
  38.                 mx_j = i;
  39.             }
  40.         }
  41.         if(mx == -1) {
  42.             cout << "Route " << ti << " has no nice parts\n";
  43.         }
  44.         else {
  45.             cout << "The nicest part of route " << ti << " is between stops " << mx_i+1 << " and " << mx_j+2 << "\n";
  46.         }
  47.     }
  48.     return 0;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement