結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー tnakao0123tnakao0123
提出日時 2019-12-14 23:11:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 106 ms / 2,500 ms
コード長 1,397 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 85,600 KB
実行使用メモリ 12,564 KB
最終ジャッジ日時 2023-09-10 12:07:40
合計ジャッジ時間 3,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
12,268 KB
testcase_01 AC 7 ms
12,272 KB
testcase_02 AC 5 ms
12,312 KB
testcase_03 AC 7 ms
12,552 KB
testcase_04 AC 8 ms
12,280 KB
testcase_05 AC 9 ms
12,304 KB
testcase_06 AC 8 ms
12,304 KB
testcase_07 AC 9 ms
12,472 KB
testcase_08 AC 9 ms
12,316 KB
testcase_09 AC 9 ms
12,468 KB
testcase_10 AC 9 ms
12,280 KB
testcase_11 AC 56 ms
12,348 KB
testcase_12 AC 66 ms
12,384 KB
testcase_13 AC 54 ms
12,340 KB
testcase_14 AC 17 ms
12,320 KB
testcase_15 AC 47 ms
12,300 KB
testcase_16 AC 82 ms
12,328 KB
testcase_17 AC 21 ms
12,564 KB
testcase_18 AC 98 ms
12,332 KB
testcase_19 AC 47 ms
12,336 KB
testcase_20 AC 18 ms
12,480 KB
testcase_21 AC 11 ms
12,320 KB
testcase_22 AC 12 ms
12,324 KB
testcase_23 AC 9 ms
12,464 KB
testcase_24 AC 56 ms
12,336 KB
testcase_25 AC 83 ms
12,432 KB
testcase_26 AC 90 ms
12,308 KB
testcase_27 AC 90 ms
12,340 KB
testcase_28 AC 106 ms
12,420 KB
testcase_29 AC 60 ms
12,340 KB
testcase_30 AC 25 ms
12,304 KB
testcase_31 AC 14 ms
12,408 KB
testcase_32 AC 88 ms
12,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 949.cc:  No.949 飲酒プログラミングコンテスト - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 3000;

/* typedef */

/* global variables */

int as[MAX_N + 1], bs[MAX_N + 1], ds[MAX_N];
bool dp[MAX_N + 1][MAX_N + 1];

/* subroutines */

bool check(int k) {
  memset(dp, false, sizeof(dp));
  dp[0][0] = true;

  for (int i = 0; i < k; i++)
    for (int j = 0; i + j < k; j++)
      if (dp[i][j]) {
	int dij = ds[k - 1 - (i + j)];
	if (as[i + 1] + bs[j] >= dij) dp[i + 1][j] = true;
	if (as[i] + bs[j + 1] >= dij) dp[i][j + 1] = true;
      }

  for (int i = 0; i <= k; i++)
    if (dp[i][k - i]) return true;
  return false;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i <= n; i++) scanf("%d", as + i);
  for (int i = 0; i <= n; i++) scanf("%d", bs + i);
  for (int i = 0; i < n; i++) scanf("%d", ds + i);
  sort(ds, ds + n);

  int k0 = 0, k1 = n + 1;
  while (k0 + 1 < k1) {
    int k = (k0 + k1) / 2;
    if (check(k)) k0 = k;
    else k1 = k;
  }

  printf("%d\n", k0);
  return 0;
}
0