Submission #22482437


Source Code Expand

#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#else
#include "Debug.hpp"
#endif

class Task {
 public:
  void Perform() {
    Read();
    Solve();
  }
 
 private:
  int k, n, m;  
  vector<int64_t> a;

  void Read() {
    cin >> k >> n >> m; 
    a.resize(k);
    for (auto &i : a) {
      cin >> i;
      i *= m;
    }
  }
 
  void Solve() {
    debug(a);
    vector<int64_t> b(k);
    set<pair<int64_t, int>> diffs;
    int64_t done = 0;
    for (int i = 0; i < k; ++i) {
      b[i] = a[i] + ((n - (a[i] % n)) % n);
      done += b[i] / n;
    }
    int64_t add_all = (m - done) / k;
    int64_t unit_changes = abs(m - done) % k;
    int change = (m < done) ? -n : n;
    for (int i = 0; i < k; ++i) {
      b[i] += add_all * n;
      diffs.insert({abs(b[i] - a[i]), i});
    }
    debug(b);
    debug(done);
    while (unit_changes--) {
      debug(diffs);
      pair<int64_t, int> i;
      if (change > 0) {
        i = *diffs.begin();
      } else if (add_all > 0) {
        i = *diffs.begin();
      } else {
        i = *diffs.rbegin();
      }
      b[i.second] += change;
      diffs.erase(i);
      diffs.insert({abs(b[i.second] - a[i.second]), i.second});
    }
    debug(b);
    int64_t sum = 0;
    for (int i = 0; i < k; ++i) {
      cout << b[i] / n << " \n"[i == k - 1];
      sum += b[i] / n;
    }
    debug(sum, m);
  }
};
 
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  Task t;
  t.Perform();
  return 0;
}

Submission Info

Submission Time
Task B - Village of M People
User tauhrick
Language C++ (GCC 9.2.1)
Score 0
Code Size 1560 Byte
Status WA
Exec Time 83 ms
Memory 10808 KiB

Compile Error

./Main.cpp: In member function ‘void Task::Solve()’:
./Main.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 42
      |                    ^~
./Main.cpp:30:5: note: in expansion of macro ‘debug’
   30 |     debug(a);
      |     ^~~~~
./Main.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 42
      |                    ^~
./Main.cpp:45:5: note: in expansion of macro ‘debug’
   45 |     debug(b);
      |     ^~~~~
./Main.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 42
      |                    ^~
./Main.cpp:46:5: note: in expansion of macro ‘debug’
   46 |     debug(done);
      |     ^~~~~
./Main.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 42
      |                    ^~
./Main.cpp:48:7: note: in expansion of macro ‘debug’
   48 |       debug(diffs);
      |       ^~~~~
./Main.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 42
      |                    ^~
./Main.cpp:61:5: note: in expansion of macro ‘debug’
   61 |     debug(b);
      |     ^~~~~
./Main.cpp:4:20: warning: statement has no effect [-Wunused-value]
    4 | #define debug(...) 42
      |                    ^~
./Main.cpp:67:5: note: in expansion of macro ‘debug’
   67 |     debug(sum, m);
      |     ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 40
WA × 20
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_rand_01.txt, 02_rand_02.txt, 02_rand_03.txt, 02_rand_04.txt, 02_rand_05.txt, 02_rand_06.txt, 02_rand_07.txt, 02_rand_08.txt, 02_rand_09.txt, 02_rand_10.txt, 02_rand_11.txt, 02_rand_12.txt, 02_rand_13.txt, 02_rand_14.txt, 02_rand_15.txt, 02_rand_16.txt, 02_rand_17.txt, 02_rand_18.txt, 02_rand_19.txt, 02_rand_20.txt, 03_small_N_01.txt, 03_small_N_02.txt, 03_small_N_03.txt, 03_small_N_04.txt, 03_small_N_05.txt, 03_small_N_06.txt, 03_small_N_07.txt, 03_small_N_08.txt, 03_small_N_09.txt, 03_small_N_10.txt, 04_small_M_01.txt, 04_small_M_02.txt, 04_small_M_03.txt, 04_small_M_04.txt, 04_small_M_05.txt, 04_small_M_06.txt, 04_small_M_07.txt, 04_small_M_08.txt, 04_small_M_09.txt, 04_small_M_10.txt, 05_small_NM_01.txt, 05_small_NM_02.txt, 05_small_NM_03.txt, 05_small_NM_04.txt, 05_small_NM_05.txt, 05_small_NM_06.txt, 05_small_NM_07.txt, 05_small_NM_08.txt, 05_small_NM_09.txt, 05_small_NM_10.txt, 06_numerical_error_01.txt, 06_numerical_error_02.txt, 06_numerical_error_03.txt, 06_numerical_error_04.txt, 06_numerical_error_05.txt, 07_handmade_01.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 3 ms 3508 KiB
01_sample_02.txt AC 2 ms 3632 KiB
01_sample_03.txt AC 3 ms 3536 KiB
01_sample_04.txt AC 2 ms 3560 KiB
02_rand_01.txt AC 60 ms 9236 KiB
02_rand_02.txt WA 44 ms 7276 KiB
02_rand_03.txt WA 64 ms 9628 KiB
02_rand_04.txt AC 70 ms 10184 KiB
02_rand_05.txt WA 23 ms 5272 KiB
02_rand_06.txt WA 22 ms 5288 KiB
02_rand_07.txt AC 46 ms 7548 KiB
02_rand_08.txt AC 36 ms 6496 KiB
02_rand_09.txt WA 56 ms 8968 KiB
02_rand_10.txt AC 48 ms 8164 KiB
02_rand_11.txt WA 70 ms 10232 KiB
02_rand_12.txt AC 10 ms 3676 KiB
02_rand_13.txt WA 47 ms 7424 KiB
02_rand_14.txt WA 73 ms 10760 KiB
02_rand_15.txt AC 21 ms 4900 KiB
02_rand_16.txt AC 26 ms 5480 KiB
02_rand_17.txt WA 8 ms 3908 KiB
02_rand_18.txt WA 31 ms 5796 KiB
02_rand_19.txt WA 33 ms 6020 KiB
02_rand_20.txt WA 20 ms 4816 KiB
03_small_N_01.txt AC 54 ms 10028 KiB
03_small_N_02.txt WA 29 ms 6308 KiB
03_small_N_03.txt WA 32 ms 6424 KiB
03_small_N_04.txt WA 26 ms 6596 KiB
03_small_N_05.txt WA 49 ms 9136 KiB
03_small_N_06.txt AC 51 ms 9656 KiB
03_small_N_07.txt WA 32 ms 6536 KiB
03_small_N_08.txt WA 50 ms 9744 KiB
03_small_N_09.txt WA 48 ms 10268 KiB
03_small_N_10.txt WA 29 ms 6052 KiB
04_small_M_01.txt AC 35 ms 6496 KiB
04_small_M_02.txt AC 34 ms 6104 KiB
04_small_M_03.txt AC 15 ms 4436 KiB
04_small_M_04.txt AC 58 ms 8156 KiB
04_small_M_05.txt AC 22 ms 4504 KiB
04_small_M_06.txt AC 8 ms 4000 KiB
04_small_M_07.txt AC 64 ms 8596 KiB
04_small_M_08.txt AC 83 ms 10800 KiB
04_small_M_09.txt AC 8 ms 3688 KiB
04_small_M_10.txt AC 29 ms 5324 KiB
05_small_NM_01.txt AC 39 ms 7900 KiB
05_small_NM_02.txt AC 14 ms 4664 KiB
05_small_NM_03.txt AC 48 ms 8344 KiB
05_small_NM_04.txt AC 13 ms 4440 KiB
05_small_NM_05.txt AC 29 ms 5940 KiB
05_small_NM_06.txt AC 48 ms 8576 KiB
05_small_NM_07.txt AC 66 ms 10808 KiB
05_small_NM_08.txt AC 58 ms 10280 KiB
05_small_NM_09.txt AC 13 ms 4344 KiB
05_small_NM_10.txt AC 14 ms 4236 KiB
06_numerical_error_01.txt AC 29 ms 6992 KiB
06_numerical_error_02.txt AC 8 ms 3804 KiB
06_numerical_error_03.txt AC 20 ms 6372 KiB
06_numerical_error_04.txt AC 32 ms 7552 KiB
06_numerical_error_05.txt AC 19 ms 6308 KiB
07_handmade_01.txt AC 4 ms 3584 KiB