結果
| 問題 | 
                            No.288 貯金箱の仕事
                             | 
                    
| コンテスト | |
| ユーザー | 
                             char134217728
                         | 
                    
| 提出日時 | 2017-07-30 07:14:27 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 912 bytes | 
| コンパイル時間 | 1,359 ms | 
| コンパイル使用メモリ | 158,224 KB | 
| 実行使用メモリ | 5,504 KB | 
| 最終ジャッジ日時 | 2024-10-10 21:57:51 | 
| 合計ジャッジ時間 | 4,350 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 53 | 
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   17 | main(){
      | ^~~~
            
            ソースコード
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const ll inf = 1e18;
const int mod = 1e9+7;
ll dp[250001];
ll n, m, a[500], k[500], q;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, n)cin >> a[i];
  FOR(i, 0, n)cin >> k[i];
  q = a[n - 1];
  q *= q;
  FOR(i, 1, q)dp[i] = inf;
  m *= -1;
  FOR(i, 0, n)m += a[i] * k[i];
  if(m < 0){
    cout << -1 << endl;
    return 0;
  }
  FORR(i, n-1, 0){
    ll d = a[i];
    FOR(j, d, q){
      dp[j] = min(dp[j], dp[j - d] + 1);
    }
  }
  ll t = 0;
  if(m >= q){
    t = (m - q)/a[n-1] + 1;
    m -= t * a[n-1];
  }
  t += dp[m];
  if(t >= inf)t = -2;
  cout << t << endl;
  //FOR(i, 0, q)cout << i << ":" << dp[i] << endl;
}
            
            
            
        
            
char134217728