forked from RyanFehr/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
37 lines (31 loc) · 916 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Problem: https://www.hackerrank.com/challenges/jumping-on-the-clouds-revisited
//Java 8
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int c[] = new int[n];
for(int c_i=0; c_i < n; c_i++){
c[c_i] = in.nextInt();
}
int energy = 100;
int cloud = 0;
do
{
energy--; //You performed a jump
cloud = (cloud + k) % n;
if(c[cloud] == 1)
{
energy -= 2;//You landed on a thundercloud
}
}
while(cloud != 0);
System.out.println(energy);
}
}