|
|
back to boardimport java.util.Scanner; public class MEGA { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int capacity = sc.nextInt(); int minutes = sc.nextInt(); int stoppedcars = 0; for (int i=1; i<=minutes; i++) { int thisminutecars = sc.nextInt(); if (thisminutecars > capacity) stoppedcars = thisminutecars - capacity; if (thisminutecars < capacity) stoppedcars = stoppedcars - (capacity - thisminutecars); } if (stoppedcars < 0) stoppedcars = 0; System.out.println(stoppedcars);
} } Edited by author 17.09.2012 17:51 Step through in the debugger and see if the changes to stoppedcars makes sense to you. Do you properly handle cars left over from previous minutes? |
|
|