結果
問題 |
No.1676 Coin Trade (Single)
|
ユーザー |
![]() |
提出日時 | 2021-09-11 01:39:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 880 bytes |
コンパイル時間 | 2,223 ms |
コンパイル使用メモリ | 198,540 KB |
最終ジャッジ日時 | 2025-01-24 12:37:32 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} int main(){ int n,k; cin>>n>>k; vector g(n,vector<int>()); vector<int> a(n); rep(i,0,n){ int m; cin>>a[i]>>m; rep(j,0,m){ int p; cin>>p; g[p-1].push_back(i); } } vector<ll> dp(n,-INF); dp[0]=0; rep(i,0,n){ if(i!=n-1)chmax(dp[i+1],dp[i]); for(auto& to:g[i])chmax(dp[to],dp[i]+max(0,a[to]-a[i])); } cout<<dp[n-1]<<'\n'; return 0; }