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

WA10
Posted by rishi2110 5 Aug 2013 00:42
Hi i'm getting WA for #10, can anyone help with this?
My code works for everything ive tested so far
public static void main( String [] args){
    int a,b;
    Scanner sc = new Scanner(System.in);
    a = sc.nextInt();
    b = sc.nextInt();
    int[] array = new int[b];
    for( int i = 0; i < b; i++)
        array[i] = sc.nextInt();
    int carry = 0;
    for( int i = 0; i < b; i++){
        array[i] = array[i] + carry;
        if(array[i] > a)
        carry = array[i]%a;
        else carry = 0;
                array[i] = array[i] - carry;
    }
    int answer=0;
    array[b-1]+=carry;
    int current  = 0;
    for( int i = 0; i < b; i++){
        if(array[current] <= a){
        array[current] = 0;
        current++;
        }
        else
        array[current] = array[current] - a;
    }
        for( int i = 0; i < b; i++)
            answer+=array[i];
        System.out.println(answer);

}

Edited by author 05.08.2013 14:55

Edited by author 05.08.2013 17:31