#include <cstring>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAX = 20000+5;
int A[MAX];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int b;
scanf("%d", &b);
for(int i=1; i<=b; i++) {
int s;
scanf("%d", &s);
for(int j=1; j<s; j++) {
scanf("%d", &A[j]);
}
int max_sum = -(1<<30);
int min_sum = 0;
int sum = 0;
int temp=1, st, ed;
for(int j=1; j<s; j++) {
sum += A[j];
if(sum-min_sum > max_sum ||
(sum-min_sum == max_sum && j+1-temp > ed-st)) {
max_sum =sum-min_sum;
st = temp;
ed = j+1;
}
if(sum<min_sum) {
min_sum = sum;
temp = j+1;
}
}
if(max_sum > 0) {
printf("The nicest part of route %d is between stops %d and %d\n",
i, st, ed);
} else {
printf("Route %d has no nice parts\n", i);
}
}
return 0;
}
UVa 507 - Jill Rides Again
最新推荐文章于 2016-07-27 22:50:36 发布