結果
| 問題 |
No.288 貯金箱の仕事
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-10-10 07:10:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 1,091 bytes |
| コンパイル時間 | 699 ms |
| コンパイル使用メモリ | 75,848 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 04:56:57 |
| 合計ジャッジ時間 | 4,090 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 53 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
int main(){
long long n,m;
cin >> n >> m;
vector<long long> a(n), k(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
for(int i=0; i<n; i++){
cin >> k[i];
}
long long sum = 0;
for(int i=0; i<n; i++){
sum += a[i] * k[i];
}
sum -= m;
if(sum<0){
cout << -1 << endl;
return 0;
}
long long cnt = 0;
long long sz = a[n-1]*a[n-1]+1;
vector<long long> dp(sz, 1LL<<50);
dp[0] = 0;
for(int i=0; i<n; i++){
for(long long v=a[i]; v<sz; v++){
dp[v] = min(dp[v], dp[v-a[i]] + 1);
}
}
auto check = [&](long long x){
return a.back()*a.back() < sum - x*a.back();
};
long long lb = sum/(a.back()*a.back());
lb *= a.back();
/*
long long ub = 1e13;
while(ub-lb>1){
long long mid = (lb+ub)/2;
bool ok = check(mid);
(ok? lb : ub) = mid;
}
*/
cnt += lb;
sum -= lb*a.back();
cnt = dp[sum]!=(1LL<<50)?(cnt+dp[sum]):-1;
cout << cnt << endl;
return 0;
}
koyumeishi