Advertisement
ivanov_ivan

TruckTour

May 21st, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. package StacksAndQueues;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TruckTour {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.        
  9.         int n = sc.nextInt();
  10.  
  11.         int sum = 0;
  12.         int startIndex = 0;
  13.  
  14.         for (int i = 0; i < n; i++) {
  15.             int petrol = sc.nextInt();
  16.             int distance = sc.nextInt();
  17.             sum += petrol - distance;
  18.  
  19.             if (sum < 0) {
  20.                 sum = 0;
  21.                 startIndex = i + 1;
  22.             }
  23.         }
  24.         System.out.println(startIndex);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement