結果

問題 No.860 買い物
ユーザー LayCurseLayCurse
提出日時 2019-08-09 22:51:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,764 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 198,556 KB
実行使用メモリ 5,832 KB
最終ジャッジ日時 2023-09-26 21:12:38
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,504 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 8 ms
5,796 KB
testcase_08 AC 9 ms
5,724 KB
testcase_09 AC 8 ms
5,672 KB
testcase_10 AC 9 ms
5,596 KB
testcase_11 AC 7 ms
5,620 KB
testcase_12 AC 7 ms
5,620 KB
testcase_13 AC 8 ms
5,716 KB
testcase_14 AC 9 ms
5,668 KB
testcase_15 AC 4 ms
5,776 KB
testcase_16 AC 8 ms
5,624 KB
testcase_17 AC 9 ms
5,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int C[100000];
int D[100000];
long long up[100001];
long long dw[100001];
int main(){
  int a, b, i, j, k;
  long long res=0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(C[Lj4PdHRW]);
      rd(D[Lj4PdHRW]);
    }
  }
  D[0] += 1000000000;
  for(i=0;i<(N);i++){
    res += C[i];
  }
  for(i=0;i<(N);i++){
    res += D[i];
  }
  for(i=0;i<(N);i++){
    up[i+1] =max_L(up[i], dw[i] + D[i]);
    dw[i+1] =max_L(max_L(dw[i], up[i] - C[i]), dw[i] + D[i] - C[i]);
  }
  res -= dw[N];
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190806-1 [beta]

// --- original code ---
// int N, C[1d5], D[1d5];
// 
// ll up[100001], dw[100001];
// 
// {
//   int i, j, k;
//   int a, b;
//   ll res = 0;
//   rd(N,(C,D)(N));
// 
//   D[0] += 1d9;
//   rep(i,N) res += C[i];
//   rep(i,N) res += D[i];
// 
//   rep(i,N){
//     up[i+1] = max(up[i], dw[i] + D[i]);
//     dw[i+1] = max(dw[i], up[i] - C[i], dw[i] + D[i] - C[i]);
//   }
// 
//   res -= dw[N];
//   wt(res);
// }
0