結果
問題 | No.1160 Strange Bowling |
ユーザー |
![]() |
提出日時 | 2020-08-12 00:13:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 767 bytes |
コンパイル時間 | 1,860 ms |
コンパイル使用メモリ | 171,148 KB |
実行使用メモリ | 10,112 KB |
最終ジャッジ日時 | 2024-10-09 12:02:19 |
合計ジャッジ時間 | 3,329 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=(0);i<(n);i++)using namespace std;typedef long long ll;template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }int main(){cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<ll> p(n), a(n);rep(i, n) cin >> p[i] >> a[i];vector<vector<ll>> dp(n, vector<ll>(2, 0));dp[n-1][0] = p[n-1];dp[n-1][1] = p[n-1];for(int i = n - 2; i >= 0; i--){chmax(dp[i][0], dp[i+1][0] + p[i]);chmax(dp[i][0], dp[i+1][1] + p[i]);chmax(dp[i][1], dp[i+1][0] + a[i] + p[i+1]);chmax(dp[i][1], dp[i+1][1] + a[i] + a[i+1]);}cout << max(dp[0][0], dp[0][1]) << endl;}