Submission #10373487


Source Code Expand

Copy
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int a = sc.nextInt();
		Monster[] monsters = new Monster[n];
		for (int i = 0; i < n; i++) {
		    monsters[i] = new Monster(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(monsters);
		ArrayDeque<Bomb> bombs = new ArrayDeque<>();
		long total = 0;
		long damage = 0;
		for (int i = 0; i < n; i++) {
		    while (bombs.size() > 0 && bombs.peek().position < monsters[i].position) {
		        damage -= bombs.poll().power;
		    }
		    monsters[i].power -= damage;
		    if (monsters[i].power > 0) {
		        int count = (int)((monsters[i].power + a - 1) / a);
		        total += count;
		        bombs.add(new Bomb(monsters[i].position + d * 2, count * a));
		        damage += count * a;
		    }
		}
		System.out.println(total);
   }
   
   static class Monster implements Comparable<Monster> {
       int position;
       long power;
       
       public Monster(int position, long power) {
           this.position = position;
           this.power = power;
       }
       
       public int compareTo(Monster another) {
           return position - another.position;
       }
   }
   
   static class Bomb implements Comparable<Bomb> {
       int position;
       long power;
       
       public Bomb(int position, long power) {
           this.position = position;
           this.power = power;
       }
       
       public int hashCode() {
           return position;
       }
       
       public boolean equals(Object o) {
           Bomb b = (Bomb) o;
           return b.position == position && b.power == power;
       }
       
       public int compareTo(Bomb another) {
           if (another.position == position) {
               return (int)(power - another.power);
           } else {
               return position - another.position;
           }
       }
   }
}

Submission Info

Submission Time
Task F - Silver Fox vs Monster
User HMaekawa
Language Java8 (OpenJDK 1.8.0)
Score 600
Code Size 2036 Byte
Status
Exec Time 1048 ms
Memory 114124 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 600 / 600 sample_01, sample_02, sample_03, max_01, max_02, max_03, max_04, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, random_16, hand_01, hand_02
after_contest 0 / 0 after_contest_01
Case Name Status Exec Time Memory
after_contest_01 782 ms 102704 KB
hand_01 95 ms 19924 KB
hand_02 93 ms 23892 KB
max_01 1005 ms 102672 KB
max_02 1048 ms 100060 KB
max_03 775 ms 114124 KB
max_04 742 ms 100168 KB
random_01 573 ms 59184 KB
random_02 411 ms 48020 KB
random_03 910 ms 98684 KB
random_04 735 ms 85636 KB
random_05 1000 ms 102232 KB
random_06 661 ms 89376 KB
random_07 341 ms 40504 KB
random_08 948 ms 98704 KB
random_09 379 ms 48384 KB
random_10 689 ms 74212 KB
random_11 274 ms 42188 KB
random_12 607 ms 62736 KB
random_13 757 ms 91668 KB
random_14 506 ms 56552 KB
random_15 1002 ms 98664 KB
random_16 1042 ms 98308 KB
sample_01 91 ms 21844 KB
sample_02 93 ms 18640 KB
sample_03 92 ms 19796 KB