Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Guliguli {
  4.     public static void main(String[] args) {
  5.         Scanner in = new Scanner(System.in);
  6.  
  7.         int n = in.nextInt();
  8.         int s = in.nextInt();
  9.  
  10.         long[] times = new long[n];
  11.         long answ = 0;
  12.         for (int i = 0; i < n; i++) {
  13.             long curTime = i + s * in.nextInt();
  14.             int pos = i;
  15.             while(pos > 0 && times[pos] > curTime) {
  16.                 times[pos + 1] = times[pos];
  17.                 pos--;
  18.                 answ++;
  19.             }
  20.             times[pos] = curTime;
  21.         }
  22.  
  23.         System.out.println(answ);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement