結果

問題 No.1163 I want to be a high achiever
ユーザー outlineoutline
提出日時 2020-12-27 18:34:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 2,019 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 138,228 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 18:17:36
合計ジャッジ時間 2,759 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 4 ms
6,948 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 5 ms
6,940 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, X;
    cin >> N >> X;
    vector<int> A(N), B(N);
    for(int i = 0; i < N; ++i)  cin >> A[i];
    for(int i = 0; i < N; ++i)  cin >> B[i];

    // 平均が X 以上となる条件 : \sum(A-X)>=0
    // A-X>=0 ならば算出対象に入れる

    // S = A-X(>=0) の総和
    // costsum = (A-X<0) なる B の総和
    int S = 0, costsum = 0;
    vector<P> dat;
    for(int i = 0; i < N; ++i){
        if(A[i] - X >= 0)   S += A[i] - X;
        else{
            dat.emplace_back(X - A[i], B[i]);
            costsum += B[i];
        }
    }

    // すべて A-X<0 なら -1
    if((int)dat.size() == N){
        cout << -1 << endl;
        return 0;
    }

    // dp[s] := A-X(<0) の総和が -s のときの B の総和の最大値
    vector<int> dp(S + 1, -1);
    dp[0] = 0;
    for(auto [C, D] : dat){
        for(int i = S - C; i >= 0; --i){
            if(dp[i] != -1) chmax(dp[i + C], dp[i] + D);
        }
    }
    
    cout << costsum - *max_element(begin(dp), end(dp)) << endl;

    return 0;
}
0