Submission #70991682


Source Code Expand

// **** I/O & small utilities ****
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <iterator> // iterator helpers: back_inserter, istream/ostream_iterator, next/prev, distance
#include <numeric>
#include <utility> // pair, move, forward, swap, tie, make_pair - lightweight helpers

// **** Core algorithms & numeric helpers ****
#include <algorithm> // sort, stable_sort, nth_element, partial_sort, binary_search, next_permutation, min/max, accumulate
#include <bitset> // fixed-size bitmasks, fast bit ops, count(), useful for mask DP & boolean arrays

// **** Sequence containers ****
#include <array> // std::array: fixed-size array with container interface (stack-allocated)
#include <deque> // double-ended queue: O(1) push/pop front/back, sliding-window, 0-1 BFS
#include <forward_list> // singly-linked list: low-overhead single-linked ops, O(1) insert_after/erase_after
#include <list> // doubly-linked list: splice, O(1) insert/erase with iterators, stable node-based ops
#include <vector> // dynamic array: push_back, reserve, random access - most used container

// **** Container adapters & heaps ****
#include <queue> // queue (FIFO), priority_queue (max/min heap) - BFS, Dijkstra, k-largest, sliding window heaps
#include <stack> // stack adapter (LIFO) - simple DFS, expression parsing

// **** Associative containers ****
#include <map> // ordered map/multimap (RB-tree): log(N) insert/find, ordered traversal, lower_bound, higher_bound
#include <set> // ordered set/multiset: log(N) membership, ordered operations and range queries, lower_bound, higher_bound
#include <unordered_map> // hash map: average O(1) lookup/insert - freq counters, memoization
#include <unordered_set> // hash set: average O(1) membership - deduplication, visited sets

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using namespace std;

// generic alias - lexicographic min-heap by pair<T1,T2>
template <typename T1, typename T2, typename Compare = greater<pair<T1, T2>>>
using min_heap_pair = priority_queue<pair<T1, T2>, vector<pair<T1, T2>>, Compare>;

// // comparator template - min-heap comparing only by .first
// template <typename T1, typename T2> struct CompareFirst {
//   bool operator()(const pair<T1, T2> &a, const pair<T1, T2> &b) const {
//     return a.first < b.first; // smaller first => higher priority (min-heap)
//   }
// };

// // optional factory function to deduce types
// template <typename T1, typename T2, typename Compare = greater<pair<T1, T2>>>
// auto make_min_heap() {
//   return min_heap_pair<T1, T2, Compare>{};
// }

// struct MyType {
//   u64 data;
//   ...
//   bool operator<(const MyType &other) const { return this->data < other.data; }
// };

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(nullptr);

  i64 N, X, Y;
  cin >> N >> X >> Y;

  vector<i64> A(N);
  for (auto &e : A) {
    cin >> e;
  }

  vector<i64> XANS(N, 0);
  vector<i64> YANS(N, 0);
  vector<i64> weights(N);

  sort(A.begin(), A.end());

  i64 wmin = A[0] * X;
  i64 wmax = A[0] * Y;

  for (i64 i = 0; i < A.size(); i++) {
    auto a_wmin = A[i] * X;
    auto a_wmax = A[i] * Y;

    if (!(a_wmin >= wmin && a_wmin <= wmax)) {
      cout << -1 << '\n';
      return 0;
    }

    weights[i] = a_wmax;
    YANS[i] = A[i];
    XANS[i] = 0;
  }

  auto d = Y - X;

  for (i64 i = 1; i < weights.size(); i++) {
    auto D = abs(weights[0] - weights[i]);

    if (D % d == 0) {
      XANS[i] += D / d;
      YANS[i] -= D / d;
      weights[i] -= D;

      if (i == weights.size() - 1) {
        cout << accumulate(YANS.begin(), YANS.end(), 0ll) << '\n';
        return 0;
      }
    } else {
      break;
    }
  }

  cout << -1 << '\n';

  return 0;
}

Submission Info

Submission Time
Task C - Candy Tribulation
User mrdcvlsc
Language C++23 (GCC 15.2.0)
Score 350
Code Size 3941 Byte
Status AC
Exec Time 23 ms
Memory 9628 KiB

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:87:21: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for (i64 i = 0; i < A.size(); i++) {
      |                   ~~^~~~~~~~~~
./Main.cpp:103:21: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |   for (i64 i = 1; i < weights.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~
./Main.cpp:111:13: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |       if (i == weights.size() - 1) {
      |           ~~^~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 46
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 3532 KiB
00-sample-02.txt AC 1 ms 3548 KiB
00-sample-03.txt AC 1 ms 3632 KiB
01-01.txt AC 11 ms 6348 KiB
01-02.txt AC 3 ms 4096 KiB
01-03.txt AC 14 ms 7120 KiB
01-04.txt AC 15 ms 7428 KiB
01-05.txt AC 9 ms 9472 KiB
01-06.txt AC 12 ms 9548 KiB
01-07.txt AC 12 ms 9604 KiB
01-08.txt AC 22 ms 9424 KiB
01-09.txt AC 23 ms 9424 KiB
01-10.txt AC 22 ms 9500 KiB
01-11.txt AC 22 ms 9548 KiB
01-12.txt AC 21 ms 9612 KiB
01-13.txt AC 16 ms 8144 KiB
01-14.txt AC 22 ms 9480 KiB
01-15.txt AC 22 ms 9556 KiB
01-16.txt AC 21 ms 9016 KiB
01-17.txt AC 22 ms 9476 KiB
01-18.txt AC 22 ms 9424 KiB
01-19.txt AC 20 ms 8908 KiB
01-20.txt AC 22 ms 9628 KiB
01-21.txt AC 22 ms 9612 KiB
01-22.txt AC 21 ms 9168 KiB
01-23.txt AC 22 ms 9476 KiB
01-24.txt AC 22 ms 9528 KiB
01-25.txt AC 18 ms 8376 KiB
01-26.txt AC 12 ms 6720 KiB
01-27.txt AC 19 ms 8788 KiB
01-28.txt AC 17 ms 8012 KiB
01-29.txt AC 22 ms 9424 KiB
01-30.txt AC 22 ms 9480 KiB
01-31.txt AC 15 ms 7300 KiB
01-32.txt AC 22 ms 9548 KiB
01-33.txt AC 22 ms 9548 KiB
01-34.txt AC 18 ms 8220 KiB
01-35.txt AC 22 ms 9580 KiB
01-36.txt AC 23 ms 9548 KiB
01-37.txt AC 12 ms 6864 KiB
01-38.txt AC 21 ms 9548 KiB
01-39.txt AC 22 ms 9612 KiB
01-40.txt AC 18 ms 8460 KiB
01-41.txt AC 16 ms 8204 KiB
01-42.txt AC 13 ms 7096 KiB
01-43.txt AC 22 ms 9532 KiB