結果

問題 No.949 飲酒プログラミングコンテスト
ユーザー TAISA_
提出日時 2019-12-15 13:14:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 174,732 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2024-07-02 18:12:16
合計ジャッジ時間 4,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 WA * 15 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), d(n), i1(n + 1), i2(n + 1);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    sort(all(d));
    reverse(all(d));
    for (int i = 1; i <= n; i++) {
        if (a[i1[i - 1]] - a[i1[i - 1] + 1] < b[i2[i - 1]] - b[i2[i - 1] + 1]) {
            i1[i] = i1[i - 1] + 1;
            i2[i] = i2[i - 1];
        } else {
            i2[i] = i2[i - 1] + 1;
            i1[i] = i1[i - 1];
        }
        // cout << i1[i] << " " << i2[i] << endl;
    }
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i + 1][j] |= dp[i][j];
            if (j > 0) {
                if (a[i1[j]] + b[i2[j]] >= d[i]) {
                    dp[i + 1][j] |= dp[i][j - 1];
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i <= n; i++) {
        if (dp[n][i]) {
            chmax(res, i);
        }
    }
    cout << res << endl;
}
0