結果
問題 |
No.860 買い物
|
ユーザー |
|
提出日時 | 2019-08-09 23:34:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 1,000 ms |
コード長 | 769 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 169,308 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-07-19 15:55:27 |
合計ジャッジ時間 | 2,678 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) using namespace std; using ll = long long; void chmin(ll &x, ll y) { x = min(x, y); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> C(N + 1), D(N + 1); rep(i, N) cin >> C[i] >> D[i]; const ll INF = 1e18; vector<ll> dp(N + 1, INF); vector<ll> ep(N + 1, INF); dp[0] = -D[0]; rep(i, N) { chmin(dp[i + 1], dp[i] - D[i + 1] + C[i]); chmin(dp[i + 1], dp[i]); chmin(ep[i + 1], dp[i] + C[i]); chmin(ep[i + 1], ep[i]); chmin(dp[i + 1], ep[i] - D[i + 1]); } ll sumc = 0, sumd = 0; rep(i, N) sumc += C[i], sumd += D[i]; cout << ep[N] + sumc + sumd << endl; }