結果
問題 |
No.1163 I want to be a high achiever
|
ユーザー |
|
提出日時 | 2020-08-12 18:58:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 815 ms |
コンパイル使用メモリ | 77,108 KB |
最終ジャッジ日時 | 2025-01-12 21:31:03 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:41: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’ [-Wformat=] 11 | for(int i = 0; i < n; i++) scanf("%d", a.begin()+i), a[i] -= x; | ~^ ~~~~~~~~~~~ | | | | int* __gnu_cxx::__normal_iterator<int*, std::vector<int> > main.cpp:12:41: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’ [-Wformat=] 12 | for(int i = 0; i < n; i++) scanf("%d", b.begin()+i); | ~^ ~~~~~~~~~~~ | | | | int* __gnu_cxx::__normal_iterator<int*, std::vector<int> > main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d %d", &n, &x); | ~~~~~^~~~~~~~~~~~~~~~~ main.cpp:11:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | for(int i = 0; i < n; i++) scanf("%d", a.begin()+i), a[i] -= x; | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:12:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | for(int i = 0; i < n; i++) scanf("%d", b.begin()+i); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<numeric> using namespace std; int main(){ int n, x; scanf("%d %d", &n, &x); vector<int> a(n), b(n); for(int i = 0; i < n; i++) scanf("%d", a.begin()+i), a[i] -= x; for(int i = 0; i < n; i++) scanf("%d", b.begin()+i); int k = -accumulate(a.begin(), a.end(), 0); if(*max_element(a.begin(),a.end()) < 0){ cout << -1 << endl; return 0; }else if(k <= 0){ cout << 0 << endl; return 0; } vector<int> dp(k+100, 1<<30); dp[0] = 0; for(int i = 0; i < n; i++){ if(a[i] >= 0) continue; for(int j = k+99; j >= -a[i]; j--){ dp[j] = min(dp[j], dp[j+a[i]]+b[i]); } } printf("%d\n", *min_element(dp.begin()+k, dp.end())); return 0; }