結果
| 問題 | 
                            No.1077 Noelちゃんと星々4
                             | 
                    
| コンテスト | |
| ユーザー | 
                             rxoxixyxd
                         | 
                    
| 提出日時 | 2020-06-12 21:52:56 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,383 bytes | 
| コンパイル時間 | 1,605 ms | 
| コンパイル使用メモリ | 169,764 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-24 04:53:31 | 
| 合計ジャッジ時間 | 2,587 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | WA * 19 RE * 1 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFLL = 1LL<<60;
ll calc(vector<int>& a) {
  ll ans = 0;
  int n = a.size();
  for (int i = 0; i < a.size()-2; i++) {
    if (a[i] < a[i+1] && a[i+1] > a[i+2]) {  // a < b > c -> b を max(a,c) にする
      ans += a[i+1] - max(a[i], a[i+2]);
      a[i+1] = max(a[i], a[i+2]);
    } else if (a[i] > a[i+1]) {
      ans += a[i] - a[i+1];
      a[i+1] = a[i];
    }
  }
  if (a[n-1] < a[n-2]) {
    ans += a[n-2] - a[n-1];
    a[n-1] = a[n-2];
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll ans = INFLL;
  for (int i = 0; i < 1000; i++) {
    auto b = a;
    ll tmp = i;
    b[0] -= i;
    tmp += calc(b);
    chmin(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
            
            
            
        
            
rxoxixyxd