結果
| 問題 |
No.949 飲酒プログラミングコンテスト
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-12 22:08:43 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,262 ms / 2,500 ms |
| コード長 | 1,285 bytes |
| コンパイル時間 | 2,644 ms |
| コンパイル使用メモリ | 77,728 KB |
| 実行使用メモリ | 69,296 KB |
| 最終ジャッジ日時 | 2024-06-25 18:23:49 |
| 合計ジャッジ時間 | 24,065 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
new Main().run();
}
void run() {
Scanner sc = new Scanner(System.in);
int N=sc.nextInt();
long[] A=new long[N+1];
long[] B=new long[N+1];
long[] D=new long[N];
for(int i=0;i<=N;++i){
A[i]=sc.nextLong();
}
for(int i=0;i<=N;++i){
B[i]=sc.nextLong();
}
for(int i=0;i<N;++i){
D[i]=sc.nextLong();
}
Arrays.sort(D);
int ok=0;
int ng=N+1;
while(ng-ok>1){
int middle=(ok+ng)/2;
if(check(A,B,D,middle)){
ok=middle;
}else{
ng=middle;
}
}
System.out.println(ok);
}
boolean check(long[] A, long[] B, long[] D, int curn){
int N=D.length;
boolean[][] dp=new boolean[N+1][N+1];
for(int i=0;i<dp.length;++i)
for(int j=0;j<dp[i].length;++j)
dp[i][j]=false;
dp[0][0]=true;
for(int i=1;i<=curn;++i){
for(int a=0;a<=N;++a){
int b=i-a;
if(b<0||b>N)continue;
if(D[curn-i]<=A[a]+B[b]){
if(a>0) dp[i][a]|=dp[i-1][a-1];
if(b>0) dp[i][a]|=dp[i-1][a];
}
}
}
int ans=0;
for(int i=0;i<=N;++i){
for(int j=0;j<=N;++j){
if(dp[i][j]) ans=Math.max(ans,i);
}
}
return ans>=curn;
}
void tr(Object... objects) {
System.out.println(Arrays.deepToString(objects));
}
}