Submission details
Task:Array
Sender:🍦🍧🍨
Submission time:2015-09-30 17:28:27 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#10.23 sdetails
#20.21 sdetails
#30.19 sdetails
#40.20 sdetails
#50.19 sdetails
#60.23 sdetails
#70.26 sdetails
#80.24 sdetails
#90.22 sdetails
#100.22 sdetails
#110.24 sdetails
#120.22 sdetails
#130.23 sdetails
#140.24 sdetails
#150.22 sdetails
#160.22 sdetails
#170.27 sdetails
#180.26 sdetails
#190.26 sdetails
#200.24 sdetails
#210.23 sdetails

Code

public class array {
public static void main(String[] args) {
	IO io = new IO();

	//read input
	int n = io.nextInt();
	long sum = io.nextInt();

	long[] nums = new long[n];
	int i;
	for (i=0; i<n; i++) {
		nums[i] = io.nextInt();
	}
	
	//find minimum
	long min = 0;//nums[0];
	//for (i=0; i<n; i++) {
	//	if(nums[i] < min) min = nums[i];
	//}
	//offset with minimun value
	for (i=0; i<n; i++) {
		nums[i] -= min;
	}

	//mato
	int hanta = 0;
	int paa = 0;
	long maha = nums[0];
	long maha_plus;
	long count =0;
	boolean end = false;
	while(true){
		maha_plus = maha + ((paa-hanta+1) * min);
		if(maha_plus == sum){
			count++;
			//io.println(hanta+" "+paa);
		}
		if(maha_plus <= sum && !end){
			// syö
			paa++;
			if(paa == n) end = true; else maha += nums[paa];
		}else if (maha_plus >= sum){
			// ulosta
			maha -= nums[hanta];
			hanta++;
		}
		if(end){
			maha -= nums[hanta];
			hanta++;
			if(hanta == n) break;
		}
	}
	//io.println(hanta+" "+paa);


	io.println(count);
	//DEBUG PRINTS
	// io.println(min);
	// io.println(n + "\n" + sum);
	// for (i=0; i<n; i++) {
	// 	io.print(nums[i]+" ");
	// }
	// io.println();

	io.close(); // TÄYTYY KUTSUA LOPUKSI, muuten tuloste voi jäädä kirjoittamatta
}
}

Test details

Test 1

Verdict:

input
89384 -6
-1 9 -2 0 0 -1 5 0 -8 9 10 -6 ...

correct output
2029635

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 89384
	at array.main(array.java:44)

Test 2

Verdict:

input
32688 -4
6 0 9 -10 -2 -2 -1 5 -5 -6 9 8...

correct output
321307

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 32688
	at array.main(array.java:44)

Test 3

Verdict:

input
11023 2
5 0 -1 9 -10 3 10 -10 1 -3 -8 ...

correct output
146015

user output
23

Test 4

Verdict:

input
36884 -7
6 8 2 -4 1 7 1 -7 5 3 1 -6 1 -...

correct output
471565

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 36884
	at array.main(array.java:44)

Test 5

Verdict:

input
2875 -6
-4 1 -6 -10 -2 -5 9 0 -2 9 -3 ...

correct output
9343

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2875
	at array.main(array.java:44)

Test 6

Verdict:

input
52346 -111
973 629 570 312 541 -117 332 7...

correct output
8791

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 52346
	at array.main(array.java:44)

Test 7

Verdict:

input
55283 298
593 -881 937 901 -91 -622 632 ...

correct output
7351

user output
1

Test 8

Verdict:

input
93592 -589
951 -193 -855 -692 926 -602 -6...

correct output
26431

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 93592
	at array.main(array.java:44)

Test 9

Verdict:

input
98149 942
-816 178 196 -503 654 -474 -64...

correct output
37659

user output
0

Test 10

Verdict:

input
79573 -346
-161 619 720 182 726 452 -63 -...

correct output
19690

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 79573
	at array.main(array.java:44)

Test 11

Verdict:

input
100000 -9229
-6207 -4894 -1224 8410 -2954 4...

correct output
1969

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 12

Verdict:

input
100000 4655
134 4684 8364 -7381 -1874 3429...

correct output
2353

user output
0

Test 13

Verdict:

input
100000 -5901
-4907 7494 7673 -3917 -3223 -7...

correct output
2345

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 14

Verdict:

input
100000 -2507
-845 -6674 -3174 9309 -1411 53...

correct output
2242

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 15

Verdict:

input
100000 -4850
-9232 -2843 5422 -5336 -2835 -...

correct output
3753

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 16

Verdict:

input
100000 -745023
-561148 78606 440682 608892 -3...

correct output
27

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 17

Verdict:

input
100000 987216
602043 416718 216813 720665 -6...

correct output
41

user output
0

Test 18

Verdict:

input
100000 -140762
-813926 -641015 5926 -87604 -8...

correct output
43

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 19

Verdict:

input
100000 -828680
-53023 -23367 -91278 162438 82...

correct output
27

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 20

Verdict:

input
100000 -731243595
-728764339 -159138563 36776806...

correct output
0

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:44)

Test 21

Verdict:

input
100000 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
5000050000

user output
(empty)

Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 100000
	at array.main(array.java:48)