結果

問題 No.664 超能力者Aと株価予測
ユーザー vjudge1
提出日時 2025-09-22 10:34:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 4,000 ms
コード長 677 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 163,272 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-22 10:34:29
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
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%d",&n,&m,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=405;
int n,m,k;
pair<ll,ll> f[N][25];
ll g[N][25];
int main(){
    scanf("%d%d%d",&n,&m,&k);
    ++n;
    g[0][0]=k;
    for(int i=1;i<=n;++i){
        int v;
        cin>>v;
        for(int la=0;la<=m;++la){
            g[i][la]=g[i-1][la];
            f[i][la]=f[i-1][la];
            ll cn=g[i-1][la]/v,ys=g[i-1][la]%v;
            f[i][la]=max(f[i][la],{cn,ys});
            if(la){
                g[i][la]=max(g[i][la],v*f[i-1][la-1].first+f[i-1][la-1].second);
            }
        }
    }
    ll ans=0;
    for(int i=0;i<=m;++i)ans=max(ans,g[n][i]);
    printf("%lld\n",ans);
    return 0;
}
0