Submission #51015054


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    vector<multiset<int>> mst(K);
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        mst[i % K].insert(A[i]);
    }
    vector<int> ans;
    int k = 0;
    int target = *mst[k].rbegin();
    for (int i = 0; i < N; i++) {
        if (i % K == k && A[i] == target) {
            ans.push_back(A[i]);
            mst[i % K].erase(mst[i % K].find(A[i]));
            if (N - i - 1 <= K) {
                for (int j = i + 1; j < N; j++) {
                    ans.push_back(A[j]);
                }
                break;
            }
            k = (k + 1) % K;
            target = *mst[k].rbegin();
        } else {
            mst[i % K].erase(mst[i % K].find(A[i]));
        }
    }
    for (int a : ans) {
        cout << a << " ";
    }
    cout << endl;
    return 0;
}

Submission Info

Submission Time
Task I - Maximize Array
User mtrh
Language C++ 20 (gcc 12.2)
Score 100
Code Size 1014 Byte
Status AC
Exec Time 374 ms
Memory 34712 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 60
Set Name Test Cases
Sample 00_sample_01, 00_sample_02, 00_sample_03
All 00_sample_01, 00_sample_02, 00_sample_03, 01_small_01, 01_small_02, 01_small_03, 01_small_04, 01_small_05, 02_big_01, 02_big_02, 02_big_03, 02_big_04, 02_big_05, 02_big_06, 02_big_07, 02_big_08, 02_big_09, 02_big_10, 02_big_11, 02_big_12, 02_big_13, 02_big_14, 02_big_15, 02_big_16, 02_big_17, 02_big_18, 02_big_19, 02_big_20, 02_big_21, 02_big_22, 02_big_23, 02_big_24, 02_big_25, 02_big_26, 02_big_27, 02_big_28, 02_big_29, 02_big_30, 02_big_31, 02_big_32, 02_big_33, 02_big_34, 02_big_35, 02_big_36, 02_big_37, 02_big_38, 02_big_39, 02_big_40, 02_big_41, 02_big_42, 02_big_43, 02_big_44, 02_big_45, 03_handmade_01, 03_handmade_02, 03_handmade_03, 03_handmade_04, 03_handmade_05, 03_handmade_06, 03_handmade_07
Case Name Status Exec Time Memory
00_sample_01 AC 1 ms 3524 KiB
00_sample_02 AC 1 ms 3536 KiB
00_sample_03 AC 1 ms 3480 KiB
01_small_01 AC 2 ms 3688 KiB
01_small_02 AC 2 ms 3608 KiB
01_small_03 AC 2 ms 3580 KiB
01_small_04 AC 2 ms 3564 KiB
01_small_05 AC 2 ms 3600 KiB
02_big_01 AC 109 ms 18456 KiB
02_big_02 AC 295 ms 17840 KiB
02_big_03 AC 80 ms 22632 KiB
02_big_04 AC 325 ms 18512 KiB
02_big_05 AC 309 ms 18136 KiB
02_big_06 AC 238 ms 17952 KiB
02_big_07 AC 83 ms 19736 KiB
02_big_08 AC 120 ms 18736 KiB
02_big_09 AC 324 ms 18108 KiB
02_big_10 AC 123 ms 18708 KiB
02_big_11 AC 374 ms 18452 KiB
02_big_12 AC 360 ms 18400 KiB
02_big_13 AC 272 ms 18456 KiB
02_big_14 AC 236 ms 18412 KiB
02_big_15 AC 209 ms 18452 KiB
02_big_16 AC 195 ms 18404 KiB
02_big_17 AC 176 ms 18468 KiB
02_big_18 AC 170 ms 18432 KiB
02_big_19 AC 168 ms 18616 KiB
02_big_20 AC 161 ms 18412 KiB
02_big_21 AC 159 ms 18460 KiB
02_big_22 AC 158 ms 18472 KiB
02_big_23 AC 153 ms 18408 KiB
02_big_24 AC 150 ms 18512 KiB
02_big_25 AC 142 ms 18456 KiB
02_big_26 AC 150 ms 18516 KiB
02_big_27 AC 151 ms 18468 KiB
02_big_28 AC 146 ms 18452 KiB
02_big_29 AC 143 ms 18516 KiB
02_big_30 AC 136 ms 18452 KiB
02_big_31 AC 146 ms 18620 KiB
02_big_32 AC 135 ms 18480 KiB
02_big_33 AC 140 ms 18508 KiB
02_big_34 AC 138 ms 18620 KiB
02_big_35 AC 133 ms 18460 KiB
02_big_36 AC 139 ms 18528 KiB
02_big_37 AC 137 ms 18448 KiB
02_big_38 AC 136 ms 18448 KiB
02_big_39 AC 129 ms 18480 KiB
02_big_40 AC 130 ms 18516 KiB
02_big_41 AC 337 ms 18468 KiB
02_big_42 AC 325 ms 18532 KiB
02_big_43 AC 279 ms 18476 KiB
02_big_44 AC 114 ms 18736 KiB
02_big_45 AC 90 ms 19524 KiB
03_handmade_01 AC 1 ms 3512 KiB
03_handmade_02 AC 1 ms 3528 KiB
03_handmade_03 AC 1 ms 3512 KiB
03_handmade_04 AC 129 ms 18524 KiB
03_handmade_05 AC 75 ms 32400 KiB
03_handmade_06 AC 153 ms 18444 KiB
03_handmade_07 AC 90 ms 34712 KiB