結果
| 問題 |
No.2999 Long Long Friedrice
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2025-01-10 18:20:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 2,084 bytes |
| コンパイル時間 | 10,938 ms |
| コンパイル使用メモリ | 81,460 KB |
| 実行使用メモリ | 40,044 KB |
| 最終ジャッジ日時 | 2025-01-10 18:20:48 |
| 合計ジャッジ時間 | 17,823 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 33 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
Medicine[] medicines = new Medicine[n];
for (int i = 0; i < n; i++) {
medicines[i] = new Medicine(sc.nextInt());
}
for (int i = 0; i < n; i++) {
medicines[i].setAdd(sc.nextInt());
}
Arrays.sort(medicines);
Map<Integer, Integer> map = new HashMap<>();
for (Medicine x : medicines) {
if (map.containsKey(x.sum)) {
x.sum = map.get(x.sum);
}
map.put(x.base, Math.max(x.sum, map.getOrDefault(x.base, 0)));
}
System.out.println(map.getOrDefault(1, 1));
}
static class Medicine implements Comparable<Medicine> {
int base;
int add;
int sum;
public Medicine(int base) {
this.base = base;
}
public void setAdd(int v) {
add = v;
sum = base + add;
}
public int compareTo(Medicine another) {
return another.base - base;
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten