結果
問題 |
No.1163 I want to be a high achiever
|
ユーザー |
|
提出日時 | 2022-10-22 13:51:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 982 bytes |
コンパイル時間 | 2,203 ms |
コンパイル使用メモリ | 200,376 KB |
最終ジャッジ日時 | 2025-02-08 11:15:11 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 TLE * 24 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using ld = long double; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,X; cin >> N >> X; vector<ll> A(N), B(N); rep(i,N) cin >> A[i]; rep(i,N) cin >> B[i]; ll SUMB = accumulate(B.begin(), B.end(), 0LL); ll ans = 1e18; ll MAX_A = accumulate(A.begin(), A.end(), 0LL); vector<vector<ll>> dp(MAX_A + 1, vector<ll>(N + 1, -1e18)); dp[0][0] = 0; rep(i,N) { vector<vector<ll>> nt = dp; for(int s = 0; s <= MAX_A; s++) for(int k = 0; k <= N; k++) if(s + A[i] <= MAX_A && k + 1 <= N) nt[s + A[i]][k + 1] = max(nt[s + A[i]][k + 1], dp[s][k] + B[i]); swap(dp, nt); } for(int n = 1; n <= N; n++) { for(int s = n * X; s <= MAX_A; s++) { ans = min(ans, SUMB - dp[s][n]); } } cout << (ans == ll(1e18) ? -1 : ans) << endl; }