Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Guliguli {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int s = in.nextInt();
- long[] times = new long[n];
- long answ = 0;
- for (int i = 0; i < n; i++) {
- long curTime = i + s * in.nextInt();
- int pos = i;
- while(pos > 0 && times[pos] > curTime) {
- times[pos + 1] = times[pos];
- pos--;
- answ++;
- }
- times[pos] = curTime;
- }
- System.out.println(answ);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement