Submission #31875841


Source Code Expand

#include <bits/stdc++.h>
#define sz(c) int(c.size())
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <local/debug.h>
#else
#define debug(...) (void)0
#endif

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  ll l;
  cin >> n >> l;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  priority_queue<int, vector<int>, greater<int>> q;

  rep(i, 0, n) q.emplace(a[i]);

  ll res = 0;
  while (sz(q) > 2) {
    ll x = q.top();
    q.pop();
    ll y = q.top();
    q.pop();
    res += x + y;
    debug(x, y, x + y);
    q.emplace(x + y);
  }
  ll x = q.top();
  q.pop();
  ll y = q.top();
  q.pop();

  if (x + y == l) {
    res += l;
  } else {
    ll tmp = min({x + y, l - x, l - y});
    ll h1 = l / 2, h2 = l - h1;
    if (x > y)
      swap(x, y);
    if (h1 > h2)
      swap(h1, h2);
    if (x <= h1 && y <= h2)
      tmp = min(tmp, h1 + h2);
    res += l + tmp;
  }
  cout << res << '\n';
}

Submission Info

Submission Time
Task F - Bread
User ami
Language C++ (GCC 9.2.1)
Score 0
Code Size 1101 Byte
Status WA
Exec Time 69 ms
Memory 5764 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 3
WA × 30
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 3508 KiB
example_01.txt AC 2 ms 3596 KiB
hand_00.txt WA 46 ms 5740 KiB
hand_01.txt AC 3 ms 3508 KiB
hand_02.txt WA 35 ms 5704 KiB
hand_03.txt WA 50 ms 5740 KiB
hand_04.txt WA 54 ms 5736 KiB
hand_05.txt WA 59 ms 5704 KiB
random_00.txt WA 65 ms 5672 KiB
random_01.txt WA 67 ms 5668 KiB
random_02.txt WA 68 ms 5728 KiB
random_03.txt WA 67 ms 5652 KiB
random_04.txt WA 67 ms 5740 KiB
random_05.txt WA 62 ms 5704 KiB
random_06.txt WA 69 ms 5656 KiB
random_07.txt WA 68 ms 5728 KiB
random_08.txt WA 68 ms 5728 KiB
random_09.txt WA 67 ms 5744 KiB
random_10.txt WA 62 ms 5728 KiB
random_11.txt WA 66 ms 5704 KiB
random_12.txt WA 68 ms 5732 KiB
random_13.txt WA 66 ms 5732 KiB
random_14.txt WA 68 ms 5748 KiB
random_15.txt WA 67 ms 5740 KiB
random_16.txt WA 68 ms 5764 KiB
random_17.txt WA 67 ms 5748 KiB
random_18.txt WA 68 ms 5668 KiB
random_19.txt WA 67 ms 5728 KiB
random_20.txt WA 62 ms 5760 KiB
random_21.txt WA 66 ms 5668 KiB
random_22.txt WA 67 ms 5700 KiB
random_23.txt WA 68 ms 5760 KiB
random_24.txt WA 69 ms 5760 KiB