Skip to content
Browse files

507 solved

  • Loading branch information...
1 parent ce49593 commit 2fbec884a84a22368c9e924899a8891d05679750 @ksaveljev committed May 9, 2011
Showing with 62 additions and 0 deletions.
  1. +62 −0 507.cpp
View
62 507.cpp
@@ -0,0 +1,62 @@
+#include <iostream>
+using namespace std;
+
+struct result {
+ int value;
+ int start;
+ int end;
+ result() : value(-2000000000), start(0), end(0) {}
+};
+
+int main(void) {
+ int cases;
+ int roads[20001];
+ int busstops;
+
+ cin >> cases;
+
+ for (int c = 1; c <= cases; c++) {
+ cin >> busstops;
+
+ for (int i = 0; i < busstops - 1; i++)
+ cin >> roads[i];
+
+ result best;
+ //maxSum = -2000000000;
+ //maxStartIndex = 0;
+ //maxEndIndex = 0;
+
+ result current;
+ current.value = 0;
+ //currentMaxSum = 0;
+ //currentStartIndex = 0;
+
+ for (current.end= 0; current.end < busstops - 1; current.end++) {
+ current.value += roads[current.end];
+ if (current.value > best.value) {
+ best.value = current.value;
+ best.start = current.start;
+ best.end = current.end;
+ } else if (current.value == best.value) {
+ if (current.end - current.start > best.end - best.start) {
+ best.value = current.value;
+ best.start = current.start;
+ best.end = current.end;
+ }
+ }
+
+ if (current.value < 0) {
+ current.value = 0;
+ current.start = current.end + 1;
+ }
+ }
+
+ if (best.value <= 0) {
+ cout << "Route " << c << " has no nice parts" << endl;
+ } else {
+ cout << "The nicest part of route " << c << " is between stops " << best.start + 1 << " and " << best.end + 2 << endl;
+ }
+ }
+
+ return 0;
+}

0 comments on commit 2fbec88

Please sign in to comment.
Something went wrong with that request. Please try again.