結果
| 問題 |
No.2693 Sword
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-03-25 13:36:22 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 2,293 bytes |
| コンパイル時間 | 1,899 ms |
| コンパイル使用メモリ | 78,660 KB |
| 実行使用メモリ | 50,232 KB |
| 最終ジャッジ日時 | 2024-09-30 14:04:25 |
| 合計ジャッジ時間 | 5,219 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static final long MAX = 1000000000000000000L;
static long[][] dp;
static long p;
static boolean[] isDouble;
static int[] values;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
p = sc.nextLong();
int k = sc.nextInt();
isDouble = new boolean[n];
values = new int[n];
for (int i = 0; i < n; i++) {
isDouble[i] = sc.nextInt() == 2;
values[i] = sc.nextInt();
}
dp = new long[n][k + 1];
for (long[] arr : dp) {
Arrays.fill(arr, Long.MIN_VALUE);
}
long ans = dfw(n - 1, k);
System.out.println(ans > MAX ? -1 : ans);
}
static long dfw(int idx, int v) {
if (idx + 1 < v) {
return Long.MIN_VALUE / 2;
}
if (v == 0) {
return p;
}
if (dp[idx][v] == Long.MIN_VALUE) {
dp[idx][v] = Math.max(dfw(idx - 1, v), func(isDouble[idx], values[idx], dfw(idx - 1, v - 1)));
}
return dp[idx][v];
}
static long func(boolean isD, int v, long current) {
if (isD) {
return Math.min(MAX + 1, current * 2);
} else {
return Math.min(MAX + 1, current + v);
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
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