結果

問題 No.1122 Plane Tickets
ユーザー risujiroh
提出日時 2020-07-22 22:48:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 195,124 KB
最終ジャッジ日時 2025-01-12 03:22:43
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using ll = long long;
  auto ts = [](ll l, ll r, auto f) {
    while (r - l > 2) {
      ll m = (l + r) / 2;
      if (f(m) < f(m + 1)) {
        l = m;
      } else {
        r = m + 1;
      }
    }
    return f(l + 1);
  };
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  auto g = [&](ll abe) {
    a -= abe;
    b -= abe;
    e -= abe;
    ll abc = min({a, b, c});
    ll cde = min({c - abc, d, e});
    ll bcd = min({b - abc, c - abc - cde, d - cde});
    a += abe;
    b += abe;
    e += abe;
    return abe + abc + bcd + cde;
  };
  auto f = [&](ll ade) {
    a -= ade;
    d -= ade;
    e -= ade;
    ll res = ts(-1, min({a, b, e}) + 1, g);
    a += ade;
    d += ade;
    e += ade;
    return ade + res;
  };
  cout << ts(-1, min({a, d, e}) + 1, f) << '\n';
}
0