提出 #71871833
ソースコード 拡げる
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
static class Reindeer {
long W;
long P;
long score;
public Reindeer(long W, long P) {
this.W = W;
this.P = P;
this.score = W + P;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int T = Integer.parseInt(br.readLine());
for (int t = 0; t < T; t++) {
int N = Integer.parseInt(br.readLine());
Reindeer[] reindeer = new Reindeer[N];
long totalStrength = 0;
for (int i = 0; i < N; i++) {
String[] parts = br.readLine().split(" ");
long W = Long.parseLong(parts[0]);
long P = Long.parseLong(parts[1]);
reindeer[i] = new Reindeer(W, P);
totalStrength += P;
}
Arrays.sort(reindeer, Comparator.comparingLong(r -> r.score));
long currentRidersScoreSum = 0;
int maxRiders = 0;
for (int i = 0; i < N; i++) {
currentRidersScoreSum += reindeer[i].score;
if (currentRidersScoreSum <= totalStrength) {
maxRiders++;
} else {
break;
}
}
pw.println(maxRiders);
}
pw.flush();
}
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Reindeer and Sleigh 2 |
| ユーザ | addy |
| 言語 | Java24 (OpenJDK 24.0.2) |
| 得点 | 350 |
| コード長 | 1778 Byte |
| 結果 | AC |
| 実行時間 | 688 ms |
| メモリ | 75564 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 350 / 350 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 57 ms | 39040 KiB |
| 01_test_00.txt | AC | 337 ms | 62360 KiB |
| 01_test_01.txt | AC | 379 ms | 65284 KiB |
| 01_test_02.txt | AC | 358 ms | 63092 KiB |
| 01_test_03.txt | AC | 384 ms | 61152 KiB |
| 01_test_04.txt | AC | 442 ms | 61676 KiB |
| 01_test_05.txt | AC | 538 ms | 67220 KiB |
| 01_test_06.txt | AC | 539 ms | 74104 KiB |
| 01_test_07.txt | AC | 550 ms | 74864 KiB |
| 01_test_08.txt | AC | 541 ms | 74280 KiB |
| 01_test_09.txt | AC | 302 ms | 61596 KiB |
| 01_test_10.txt | AC | 344 ms | 64780 KiB |
| 01_test_11.txt | AC | 327 ms | 63224 KiB |
| 01_test_12.txt | AC | 338 ms | 61148 KiB |
| 01_test_13.txt | AC | 379 ms | 62084 KiB |
| 01_test_14.txt | AC | 426 ms | 67080 KiB |
| 01_test_15.txt | AC | 435 ms | 75228 KiB |
| 01_test_16.txt | AC | 456 ms | 75488 KiB |
| 01_test_17.txt | AC | 446 ms | 75456 KiB |
| 01_test_18.txt | AC | 326 ms | 64392 KiB |
| 01_test_19.txt | AC | 362 ms | 65844 KiB |
| 01_test_20.txt | AC | 340 ms | 62808 KiB |
| 01_test_21.txt | AC | 390 ms | 61288 KiB |
| 01_test_22.txt | AC | 444 ms | 61912 KiB |
| 01_test_23.txt | AC | 421 ms | 65384 KiB |
| 01_test_24.txt | AC | 604 ms | 75464 KiB |
| 01_test_25.txt | AC | 583 ms | 75564 KiB |
| 01_test_26.txt | AC | 688 ms | 75104 KiB |