-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path507.cpp
43 lines (40 loc) · 885 Bytes
/
507.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
#include "bits/stdc++.h"
using namespace std;
int main(int argc, char const *argv[]) {
int TC = 1, n, c = 1;
scanf("%d",&TC);
while (TC--) {
scanf("%d",&n);
--n;
//int a[] = {4, -5, 4, -3, 4, 4, -4, 4, -5};
//int a[] = {1, -3, 2, 1, -1};
//n = 9;
//n = 5;
int a[n];
for (int i = 0; i < n; ++i) {
scanf("%d",a+i);
}
int sum = 0;
int ans = 0;
int l = 0;
int z = 0, h = 0;
for (int i = 0; i < n; i++) {
sum +=a[i];
if (sum > ans || ( (sum == ans) && ( (i - z) > (h - l)) ) ) {
ans = sum;
h = i;
l = z;
}
if (sum < 0) {
sum = 0;
z = i;
}
}
if (l == -1) l = 0;
if (ans > 0)
printf("The nicest part of route %d is between stops %d and %d\n",c++,l+2,h+2);
else
printf("Route %d has no nice parts\n",c++);
}
return 0;
}