結果

問題 No.860 買い物
ユーザー chocoruskchocorusk
提出日時 2019-08-10 03:24:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 83 ms / 1,000 ms
コード長 842 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 96,620 KB
実行使用メモリ 4,984 KB
最終ジャッジ日時 2023-09-26 23:08:07
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 76 ms
4,936 KB
testcase_08 AC 76 ms
4,924 KB
testcase_09 AC 76 ms
4,948 KB
testcase_10 AC 76 ms
4,948 KB
testcase_11 AC 57 ms
4,932 KB
testcase_12 AC 58 ms
4,916 KB
testcase_13 AC 77 ms
4,916 KB
testcase_14 AC 77 ms
4,912 KB
testcase_15 AC 30 ms
4,984 KB
testcase_16 AC 57 ms
4,920 KB
testcase_17 AC 83 ms
4,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    ll c[100010], d[100010];
    ll s=0;
    for(int i=0; i<n; i++){
        cin>>c[i]>>d[i];
        s+=c[i]+d[i];
    }
    ll dp[2];
    dp[1]=-d[0], dp[0]=-d[0]+c[0];
    for(int i=1; i<n; i++){
        dp[1]=min(dp[1], dp[0]-d[i]);
        dp[0]=min(dp[0], dp[1]+c[i]);
    }
    cout<<s+dp[0]<<endl;
    return 0;
}
0