ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1787. Turn for MEGA

what's wrong with my solution? (test 6)
Posted by tworogue 17 Sep 2012 17:15
import 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
Re: what's wrong with my solution? (test 6)
Posted by Bogatyr 21 Sep 2012 23:23
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?