UVA Online Judge solution 507 – Jill Rides Again- Solution in C++ – Volume 5
UVA Online Judge Solution 507 – Jill Rides Again | Volume 5
UVA Problem Link – https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=448
Problem Name: 507 – Jill Rides Again
Problem Number : UVA -507 – Jill Rides Againsolution
Online Judge : UVA Online Judge Solution
Volume: 5
Solution Language : C plus plus
UVA Solution 507 – Jill Rides Again Code in C/CPP:
#include <stdio.h>
int main() {
int testcase, cases = 0;
int n, x;
scanf("%d", &testcase);
while(testcase--) {
scanf("%d", &n);
int tmp = 1, st = 0xffff, ed, sum = 0, ans = 0;
for (int i = 2; i <= n; i++) {
scanf("%d", &x);
sum += x;
if (sum < 0) sum = 0, tmp = i;
if (sum >= ans) {
if (sum > ans || (sum == ans && (i - tmp > ed - st))) {
st = tmp;
ed = i;
}
ans = sum;
}
}
if (ans > 0)
printf("The nicest part of route %d is between stops %d and %dn", ++cases, st, ed);
else
printf("Route %d has no nice partsn", ++cases);
}
return 0;
}
Tags: UVA Online Judge Solution, UVA OJ Solution list, UVA Problems Solution, UVA solver, UVA all problem solution list, UVA code in C, UVA code in C++, UVA solution in C, UVA solution, UVA OJ problems solution, UVA solution, UVA online judge codes, UVA problem 507 – Jill Rides Again solution, UVA 507 – Jill Rides Again Solution in C, UVA 507 – Jill Rides Again solution in C++, UVA 507 solution in java