ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1998. The old Padawan

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{
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();
}
}