結果
| 問題 |
No.1163 I want to be a high achiever
|
| ユーザー |
|
| 提出日時 | 2020-08-14 02:39:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 702 bytes |
| コンパイル時間 | 2,144 ms |
| コンパイル使用メモリ | 194,676 KB |
| 最終ジャッジ日時 | 2025-01-12 22:16:25 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | int n,x; scanf("%d%d",&n,&x);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | rep(i,n) scanf("%d",&b[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int INF=1<<29;
int main(){
int n,x; scanf("%d%d",&n,&x);
vector<int> a(n),b(n);
rep(i,n) scanf("%d",&a[i]);
rep(i,n) scanf("%d",&b[i]);
bool ok=false;
int plus=0,minus=0;
rep(i,n){
if(a[i]>=x){
ok=true;
plus+=a[i]-x;
}
else{
minus+=x-a[i];
}
}
if(!ok) return puts("-1"),0;
if(plus>=minus) return puts("0"),0;
vector dp(50001,INF); // dp[i] = (i 点増やすために必要な最小コスト)
dp[0]=0;
rep(i,n) if(a[i]<x) {
for(int w=50000;w>=x-a[i];w--) dp[w]=min(dp[w],dp[w-(x-a[i])]+b[i]);
}
printf("%d\n",*min_element(dp.begin()+minus-plus,dp.end()));
return 0;
}