結果

問題 No.1676 Coin Trade (Single)
ユーザー Manuel1024
提出日時 2022-09-06 05:35:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 76,280 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-11-21 06:46:50
合計ジャッジ時間 3,169 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    vector<vector<int>> b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        int m; cin >> m;
        for(int j = 0; j < m; j++){
            int x; cin >> x;
            x--;
            b[i].emplace_back(x);
        }
    }

    vector<ll> dp(n+1, 0);
    for(int i = 1; i < n; i++){
        dp[i] = dp[i-1];
        for(auto &it: b[i]){
            dp[i] = max(dp[i], dp[it]+a[i]-a[it]);
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}
0