結果
| 問題 | 
                            No.288 貯金箱の仕事
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kyuna
                         | 
                    
| 提出日時 | 2019-08-09 01:30:41 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 952 bytes | 
| コンパイル時間 | 684 ms | 
| コンパイル使用メモリ | 74,652 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-18 21:17:55 | 
| 合計ジャッジ時間 | 3,524 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 37 | 
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
    int n; ll m; cin >> n >> m;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    vector<ll> k(n);
    for (ll &ki: k) cin >> ki;
    ll tot = inner_product(a.begin(), a.end(), k.begin(), 0LL);
    if (tot < m) {
        cout << -1 << endl;
        return 0;
    }
    const int ma = a.back() * a.back();
    vector<ll> dp(ma + 1, INF);
    dp[0] = 0;
    for (int ai: a) for (int j = ai; j <= ma; j++) chmin(dp[j], dp[j - ai] + 1);
    ll otsuri = tot - m;
    ll c = max(0LL, (otsuri - ma) / a.back());
    if (dp[otsuri - c * a.back()] == INF) {
        cout << -1 << endl;
    } else {
        cout << c + dp[otsuri - c * a.back()] << endl;
    }
    return 0;
}
            
            
            
        
            
kyuna