Submission #22472334


Source Code Expand

#include <bits/stdc++.h>

#define rep(i, n) for (auto i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int K, N, M;
    cin >> K >> N >> M;
    vector<int> A(K);
    rep(i, K) cin >> A[i];

    // Process
    const double rate = (double)M / N;

    // before round
    vector<double> b(K);
    rep(i, K) b[i] = A[i] * rate;

    // after the decimal point
    vector<pair<double, int>> pair_for_sort(K);
    rep(i, K) pair_for_sort[i] = make_pair(fmod(b[i], 1.0), i);
    sort(ALL(pair_for_sort));
    vector<double> fractional_parts(K);
    vector<int> indexes(K);
    rep(i, K) {
        fractional_parts[i] = pair_for_sort[i].first;
        indexes[i] = pair_for_sort[i].second;
    }

    // rounded
    vector<ll> B(K);
    rep(i, K) B[i] = (ll)round(b[i]);

    // sum B
    const ll sum_b = accumulate(ALL(B), 0);

    // adjust
    const int half =
        lower_bound(ALL(fractional_parts), 0.5) - fractional_parts.begin();

    if (sum_b > M) {
        rep(i, sum_b - M) {
            int index = (half + i) % K;
            B[indexes[index]]--;
        }
    }
    if (sum_b < M) {
        rep(i, M - sum_b) {
            int index = (half - 1 - i + K) % K;
            B[indexes[index]]++;
        }
    }

    // Output
    rep(i, K) {
        if (i > 0) cout << ' ';
        cout << B[i];
    }
    cout << endl;

    return 0;
}

Submission Info

Submission Time
Task B - Village of M People
User Koreander
Language C++ (GCC 9.2.1)
Score 400
Code Size 1527 Byte
Status AC
Exec Time 53 ms
Memory 7912 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 60
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 10 ms 3512 KiB
01_sample_02.txt AC 2 ms 3592 KiB
01_sample_03.txt AC 3 ms 3464 KiB
01_sample_04.txt AC 5 ms 3412 KiB
02_rand_01.txt AC 46 ms 6588 KiB
02_rand_02.txt AC 38 ms 5808 KiB
02_rand_03.txt AC 50 ms 7140 KiB
02_rand_04.txt AC 53 ms 7380 KiB
02_rand_05.txt AC 23 ms 4552 KiB
02_rand_06.txt AC 21 ms 4516 KiB
02_rand_07.txt AC 39 ms 5820 KiB
02_rand_08.txt AC 32 ms 5284 KiB
02_rand_09.txt AC 46 ms 6600 KiB
02_rand_10.txt AC 39 ms 6228 KiB
02_rand_11.txt AC 48 ms 7420 KiB
02_rand_12.txt AC 8 ms 3644 KiB
02_rand_13.txt AC 33 ms 5548 KiB
02_rand_14.txt AC 52 ms 7688 KiB
02_rand_15.txt AC 17 ms 4280 KiB
02_rand_16.txt AC 21 ms 4488 KiB
02_rand_17.txt AC 9 ms 3720 KiB
02_rand_18.txt AC 22 ms 4672 KiB
02_rand_19.txt AC 23 ms 4672 KiB
02_rand_20.txt AC 17 ms 4144 KiB
03_small_N_01.txt AC 41 ms 7056 KiB
03_small_N_02.txt AC 26 ms 5208 KiB
03_small_N_03.txt AC 27 ms 5436 KiB
03_small_N_04.txt AC 27 ms 5324 KiB
03_small_N_05.txt AC 41 ms 6932 KiB
03_small_N_06.txt AC 38 ms 7160 KiB
03_small_N_07.txt AC 22 ms 5272 KiB
03_small_N_08.txt AC 40 ms 7284 KiB
03_small_N_09.txt AC 44 ms 7384 KiB
03_small_N_10.txt AC 25 ms 5060 KiB
04_small_M_01.txt AC 28 ms 5496 KiB
04_small_M_02.txt AC 21 ms 4760 KiB
04_small_M_03.txt AC 15 ms 3988 KiB
04_small_M_04.txt AC 37 ms 6224 KiB
04_small_M_05.txt AC 12 ms 3940 KiB
04_small_M_06.txt AC 8 ms 3752 KiB
04_small_M_07.txt AC 39 ms 6512 KiB
04_small_M_08.txt AC 49 ms 7908 KiB
04_small_M_09.txt AC 9 ms 3660 KiB
04_small_M_10.txt AC 19 ms 4556 KiB
05_small_NM_01.txt AC 29 ms 6084 KiB
05_small_NM_02.txt AC 15 ms 3988 KiB
05_small_NM_03.txt AC 33 ms 6552 KiB
05_small_NM_04.txt AC 11 ms 3832 KiB
05_small_NM_05.txt AC 18 ms 4752 KiB
05_small_NM_06.txt AC 31 ms 6640 KiB
05_small_NM_07.txt AC 43 ms 7912 KiB
05_small_NM_08.txt AC 40 ms 7460 KiB
05_small_NM_09.txt AC 12 ms 4000 KiB
05_small_NM_10.txt AC 8 ms 3932 KiB
06_numerical_error_01.txt AC 23 ms 5584 KiB
06_numerical_error_02.txt AC 8 ms 3604 KiB
06_numerical_error_03.txt AC 20 ms 5172 KiB
06_numerical_error_04.txt AC 22 ms 5964 KiB
06_numerical_error_05.txt AC 18 ms 4984 KiB
07_handmade_01.txt AC 4 ms 3476 KiB