-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path507.cpp
More file actions
31 lines (27 loc) · 681 Bytes
/
507.cpp
File metadata and controls
31 lines (27 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;
int n, t;
int main() {
cin >> t;
for (int rr = 1; rr <= t; rr++) {
cin >> n;
int in, start = 0, end = 0, best = -99999999, c = 0, bs = 0;
for (int i = 0; i < n - 1; i++) {
cin >> in;
c += in;
if (c < 0) {
c = 0;
start = i + 1;
}
if (c > best or (best == c and i - start > end - bs)) {
best = c;
bs = start;
end = i;
}
}
if (best > 0)
cout << "The nicest part of route " << rr << " is between stops " << bs + 1 << " and " << end + 2 << endl;
else cout << "Route " << rr << " has no nice parts" << endl;
}
return 0;
}