結果

問題 No.1676 Coin Trade (Single)
ユーザー mamimume____mo
提出日時 2021-09-10 23:53:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 172,548 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-06-12 06:32:08
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000100;
const ll INFL = 2e18;
template <class T>bool chmin(T &a, T b){ if (a > b) { a = b; return true;} else return false;}
template <class T>bool chmax(T &a, T b){ if (a < b) { a = b; return true;} else return false;}

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 b;
            cin >> b;
            b--;
            B[i].push_back(b);
        }
    }


    vector<ll> dp(N,0);
    for (int i = 1;i < N;i++) {
        chmax(dp[i],dp[i-1]);
        for (int j = 0;j < B[i].size();j++) {
            chmax(dp[i],dp[B[i][j]] + A[i] - A[B[i][j]]);
        }
    }

    cout << dp[N-1] << endl;
}
0