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 1998. The old Padawan

WA #14 please help
Posted by James Gregory 27 Oct 2017 08:19
I've passed all of the user tests on here, and any test I can think of.
Still getting WA on #14.
Here's my non-working code.

import java.io.*;

public class P1998 {
    static StreamTokenizer in;
    static PrintWriter out;

    static int nextInt() throws IOException{
        do{
            in.nextToken();
        }while(in.ttype != StreamTokenizer.TT_NUMBER);
        return (int)in.nval;
    }

    public static void main(String[] args) throws IOException{
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);

        int n = nextInt();
        int m = nextInt();
        int k = nextInt();

        int[] stones = new int[n];
        int[] dropsTo = new int[n];

        int tmp = 0, j = 0;
        for(int i = 0; i < n; i++){
            stones[i] = nextInt();

            while(j < i - 1 && tmp - stones[j] > k){
                tmp -= stones[j];
                j++;
            }
            tmp += stones[i];
            dropsTo[i] = j;
        }

        j = 0;
        int moment, time = 0;
        for(int i = 0; i < m; i++){
            moment = nextInt() - time;

            time += moment;
            j += moment - 1;
            if(j >= n){
                time -= moment - n;
                j = n;
                break;
            }
            j = dropsTo[j];
        }

        out.println(time + n - j);
        out.flush();
    }
}