結果

問題 No.3681 心の沸騰石
コンテスト
ユーザー tnakao0123
提出日時 2026-09-06 18:02:43
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 276µs
コード長 1,817 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 357 ms
コンパイル使用メモリ 80,000 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-06 18:02:48
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3681.cc:  No.3681 蠢・・豐ク鬨ー遏ウ - yukicoder
 */

#include<cstdio>
#include<cassert>
#include<algorithm>
#include<functional>

using namespace std;

/* constant */

/* typedef */

using ll = long long;

/* global variables */

/* subroutines */

/* main */

int main() {
  int r, p, q, as[3], d;
  scanf("%d%d%d%d%d%d%d", &r, &p, &q, as, as + 1, as + 2, &d);
  sort(as, as + 3, greater<int>());
  //printf(" %d,%d,%d: %d,%d,%d,%d\n", r, p, q, as[0], as[1], as[2], d);
  
  int sum = 0;

  // 0. use as only
  int x0 = min(as[2], r / p);
  sum += x0;
  as[0] -= x0, as[1] -= x0, as[2] -= x0;
  r -= x0 * p;
  //printf(" %d,%d,%d: %d,%d,%d,%d\n", r, p, q, as[0], as[1], as[2], d);
  if (r < p) { printf("%d\n", sum); return 0; }
  assert(as[2] == 0);
  
  // 1. use d, as[0], as[1] (as[2] == 0)
  int x1 = min({as[1], d + (as[0] - as[1]), r / (q + p)});
  sum += x1;
  as[0] -= x1, as[1] -= x1;
  if (x1 <= d) d -= x1;
  else as[0] -= x1 - d, d = 0;
  r -= x1 * (q + p);
  //printf(" %d,%d,%d: %d,%d,%d,%d\n", r, p, q, as[0], as[1], as[2], d);
  if (r < q + p) { printf("%d\n", sum); return 0; }
  assert(as[1] == 0);

  // 2. use d, as[0] (as[1] == as[2] == 0)
  ll q2p = q * 2LL + p;
  int x2 = min({(ll)as[0], (ll)(as[0] + d) / 3, r / q2p});
  sum += x2;
  as[0] -= x2;
  if (x2 * 2 <= d) d -= x2 * 2;
  else as[0] -= x2 * 2 - d, d = 0;
  r -= x2 * q2p;
  //printf(" %d,%d,%d: %d,%d,%d,%d\n", r, p, q, as[0], as[1], as[2], d);
  if (r < q2p) { printf("%d\n", sum); return 0; }
  assert(as[0] == 0);

  // 3. use d only (as[0] == as[1] == as[2] == 0)
  ll q3p = q * 3LL + p;
  int x3 = min((ll)d / 3, r / q3p);
  sum += x3;
  d -= x3 * 3;
  r -= x3 * q3p;
  
  //printf(" %d,%d,%d: %d,%d,%d,%d\n", r, p, q, as[0], as[1], as[2], d);
  printf("%d\n", sum);
  
  return 0;
}

0