Submission details
Task:Good grades
Sender:aalto26iw_004
Submission time:2026-11-04 17:36:20 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#16ACCEPTED0.00 sdetails
#170.00 sdetails
#18ACCEPTED0.00 sdetails
#190.00 sdetails
#200.00 sdetails
#21ACCEPTED0.00 sdetails
#220.00 sdetails
#230.00 sdetails
#240.00 sdetails
#250.00 sdetails
#260.00 sdetails
#270.00 sdetails
#280.00 sdetails
#290.00 sdetails
#30--details
#31--details
#32--details
#33--details
#34--details
#35--details
#36--details
#37--details
#38--details
#390.01 sdetails
#40--details
#41--details
#42--details
#43--details
#44--details
#45--details
#46--details
#47--details
#48--details
#490.16 sdetails
#50--details
#51--details
#52--details
#53--details
#54--details
#55--details
#56--details
#57--details
#58--details
#59--details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long unsigned int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int j = 0; j < number_counts.size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:58:74: warning: narrowing conversion of 'number_counts.std::vector<std::pair<std::pair<long unsigned int, int>, int> >::size()' from 'std::vector<std::pair<std::pair<long unsigned int, int>, int> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   58 |             number_counts.push_back({{elements[i], 1}, number_counts.size()});
      |                                                        ~~~~~~~~~~~~~~~~~~^~
input/code.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [...

Code

#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>

std::pair<uint64_t, std::vector<std::vector<int>>> max_smart(int i, int n, int k, int number_groups, int in_current_group, std::vector<std::pair<std::pair<uint64_t, int>, int>> &number_counts) {
    auto number_count = number_counts[i].first;
    auto index = number_counts[i].second;

    if (i >= n or k == -1) return {0, std::vector<std::vector<int>>(number_groups)};
    
    //std::cout << "help1" << std::endl;

    auto use_as_smallest = max_smart(i+1, n, k-1, number_groups, 0, number_counts);
    use_as_smallest.first += (in_current_group+number_count.second) * number_count.first;
    //std::cout << k << " " << use_as_smallest.second.size() << std::endl;
    use_as_smallest.second[k].push_back(index);
    
    //std::cout << "help2" << std::endl;

    auto dont_use_as_smallest = max_smart(i+1, n, k, number_groups, in_current_group+number_count.second, number_counts);
    //std::cout << k << " " << dont_use_as_smallest.second.size() << std::endl;
    dont_use_as_smallest.second[k].push_back(index);
    
    //std::cout << "help3" << std::endl;

    if (use_as_smallest.first < dont_use_as_smallest.first) {
        return dont_use_as_smallest;
    } else {
        return use_as_smallest;
    }
}

int main() {
    int n, k;
    std::cin >> n >> k;

    std::vector<uint64_t> elements(n);
    for (auto &e : elements) {
        std::cin >> e;
    }

    std::vector<std::pair<std::pair<uint64_t, int>, int>> number_counts;
    std::vector<int> indexe(n);
    number_counts.reserve(500);
    for (int i = 0; i < n; ++i) {
        bool found = false;
        for (int j = 0; j < number_counts.size(); ++j) {
            if (number_counts[j].first.first == elements[i]) {
                number_counts[j].first.second++;
                found = true;
                indexe[i] = j;
                break;
            }
        }
        if (!found) {
            indexe[i] = number_counts.size();
            number_counts.push_back({{elements[i], 1}, number_counts.size()});
        }
    }
    std::sort(number_counts.rbegin(), number_counts.rend());

    std::pair<uint64_t, std::vector<std::vector<int>>> result = max_smart(0, n, k-1, k, 0, number_counts);

    //std::cout << "help" << std::endl;
    for (auto i : indexe) {
        for (int j = 0; j < result.second.size(); ++j) {
            for (int k = 0; k < result.second[j].size(); ++k) {
                if (result.second[j][k] == i) {
                    std::cout << j+1 << " ";
                }
            }
        }
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
1 1
8 

correct output
1 

user output
1 

Test 2

Verdict: ACCEPTED

input
2 2
7 6 

correct output
2 1 

user output
2 1 

Test 3

Verdict: ACCEPTED

input
2 1
7 7 

correct output
1 1 

user output
1 1 

Test 4

Verdict: ACCEPTED

input
2 2
7 1 

correct output
2 1 

user output
2 1 

Test 5

Verdict:

input
3 1
5 10 8 

correct output
1 1 1 

user output
1 1 

Test 6

Verdict:

input
3 1
6 10 2 

correct output
1 1 1 

user output
1 1 

Test 7

Verdict:

input
4 1
10 10 4 2 

correct output
1 1 1 1 

user output
1 1 

Test 8

Verdict:

input
4 4
5 1 5 4 

correct output
3 1 4 2 

user output
1 4 2 1 4 3 

Test 9

Verdict: ACCEPTED

input
4 2
1 6 7 1 

correct output
1 2 2 1 

user output
1 2 2 1 

Test 10

Verdict: ACCEPTED

input
5 3
6 8 9 7 9 

correct output
1 2 3 1 3 

user output
1 2 3 1 3 

Test 11

Verdict:

input
5 3
10 8 10 1 2 

correct output
3 2 3 1 1 

user output
3 2 3 1 

Test 12

Verdict:

input
5 3
2 1 10 6 10 

correct output
1 1 3 2 3 

user output
1 3 2 3 

Test 13

Verdict:

input
5 3
1 8 9 3 2 

correct output
1 3 3 2 1 

user output
2 3 1 1 

Test 14

Verdict:

input
5 5
10 6 2 10 9 

correct output
4 2 1 5 3 

user output
1 5 3 2 1 5 4 

Test 15

Verdict:

input
5 2
1 9 9 3 4 

correct output
1 2 2 1 1 

user output
2 2 1 1 

Test 16

Verdict: ACCEPTED

input
5 5
10 4 3 9 1 

correct output
5 3 2 4 1 

user output
5 3 2 4 1 

Test 17

Verdict:

input
5 1
3 8 4 5 10 

correct output
1 1 1 1 1 

user output
1 1 

Test 18

Verdict: ACCEPTED

input
5 5
1 10 3 9 4 

correct output
1 5 2 4 3 

user output
1 5 2 4 3 

Test 19

Verdict:

input
5 1
4 6 5 5 1 

correct output
1 1 1 1 1 

user output
1 1 1 1 

Test 20

Verdict:

input
10 6
6 8 9 7 9 6 9 5 7 7 

correct output
2 4 5 3 5 2 6 1 3 3 

user output
1 3 5 6 4 6 1 3 6 2 4 4 

Test 21

Verdict: ACCEPTED

input
10 5
10 8 10 1 2 4 10 2 3 1 

correct output
5 4 5 1 2 3 5 2 2 1 

user output
5 4 5 1 2 3 5 2 2 1 

Test 22

Verdict:

input
10 5
2 1 10 6 10 5 5 5 4 4 

correct output
1 1 5 4 5 3 3 3 2 2 

user output
1 5 4 5 3 3 3 2 2 

Test 23

Verdict:

input
10 6
1 8 9 3 2 6 6 9 5 9 

correct output
1 5 6 2 1 4 4 6 3 6 

user output
5 6 2 1 4 4 6 3 6 

Test 24

Verdict:

input
10 10
10 6 2 10 9 8 7 7 6 3 

correct output
9 3 1 10 8 7 5 6 4 2 

user output
1 2 3 10 6 4 1 2 3 10 9 8 7 7 ...

Test 25

Verdict:

input
10 3
1 9 9 3 4 10 10 5 1 7 

correct output
1 3 3 1 2 3 3 2 1 2 

user output
3 3 1 1 3 3 1 2 

Test 26

Verdict:

input
10 9
10 4 3 9 1 1 4 2 10 6 

correct output
8 4 3 7 1 1 5 2 9 6 

user output
1 2 9 6 5 8 3 3 6 4 1 2 9 7 

Test 27

Verdict:

input
10 1
3 8 4 5 10 8 5 10 4 6 

correct output
1 1 1 1 1 1 1 1 1 1 

user output
1 1 1 1 1 1 1 1 1 

Test 28

Verdict:

input
10 9
1 10 3 9 4 6 9 3 5 1 

correct output
1 9 2 7 4 6 8 3 5 1 

user output
1 2 3 9 4 8 5 7 8 4 6 1 2 3 

Test 29

Verdict:

input
10 1
4 6 5 5 1 2 4 2 1 3 

correct output
1 1 1 1 1 1 1 1 1 1 

user output
1 1 1 1 1 

Test 30

Verdict:

input
100 55
636562060 767928734 906523441 ...

correct output
32 42 50 33 51 29 50 23 35 37 ...

user output
(empty)

Test 31

Verdict:

input
100 42
773442532 122816 137572579 324...

correct output
34 1 8 16 9 13 6 20 10 19 18 3...

user output
(empty)

Test 32

Verdict:

input
100 44
198730372 27838076 590195590 4...

correct output
9 1 28 21 23 20 15 16 7 10 36 ...

user output
(empty)

Test 33

Verdict:

input
100 56
75940263 760367935 901888417 3...

correct output
6 44 51 19 8 33 36 54 29 54 1 ...

user output
(empty)

Test 34

Verdict:

input
100 97
967034924 587586158 185430194 ...

correct output
94 59 19 88 79 67 77 64 27 15 ...

user output
(empty)

Test 35

Verdict:

input
100 23
59249204 934941692 892631472 2...

correct output
2 22 21 6 10 23 12 3 15 11 19 ...

user output
(empty)

Test 36

Verdict:

input
100 90
356460601 224848374 881788059 ...

correct output
23 14 83 4 1 28 8 54 7 48 56 3...

user output
(empty)

Test 37

Verdict:

input
100 8
244103474 837431431 342493822 ...

correct output
2 7 3 5 7 5 3 6 3 5 1 1 5 3 1 ...

user output
(empty)

Test 38

Verdict:

input
100 88
11934038 257096283 933290530 4...

correct output
1 24 83 40 56 80 23 44 1 62 46...

user output
(empty)

Test 39

Verdict:

input
100 2
391337048 538883744 535937150 ...

correct output
1 2 2 2 1 1 1 1 1 1 2 1 1 1 1 ...

user output
1 1 1 1 1 2 1 1 1 1 1 2 1 2 2 ...

Test 40

Verdict:

input
200 110
636562060 767928734 906523441 ...

correct output
69 86 99 70 101 61 100 47 74 7...

user output
(empty)

Test 41

Verdict:

input
200 84
773442532 122816 137572579 324...

correct output
66 1 14 28 16 23 11 36 18 35 3...

user output
(empty)

Test 42

Verdict:

input
200 88
198730372 27838076 590195590 4...

correct output
17 3 53 42 45 40 29 30 13 18 6...

user output
(empty)

Test 43

Verdict:

input
200 111
75940263 760367935 901888417 3...

correct output
8 85 100 35 14 62 71 106 51 10...

user output
(empty)

Test 44

Verdict:

input
200 194
967034924 587586158 185430194 ...

correct output
185 114 39 173 151 128 147 124...

user output
(empty)

Test 45

Verdict:

input
200 45
59249204 934941692 892631472 2...

correct output
3 43 41 11 19 45 25 5 30 21 37...

user output
(empty)

Test 46

Verdict:

input
200 179
356460601 224848374 881788059 ...

correct output
54 33 162 8 4 61 15 113 14 99 ...

user output
(empty)

Test 47

Verdict:

input
200 16
244103474 837431431 342493822 ...

correct output
4 14 6 8 13 9 6 10 5 10 2 2 8 ...

user output
(empty)

Test 48

Verdict:

input
200 175
11934038 257096283 933290530 4...

correct output
2 40 165 67 105 157 37 77 2 11...

user output
(empty)

Test 49

Verdict:

input
200 3
391337048 538883744 535937150 ...

correct output
2 2 2 2 1 1 1 1 1 1 3 2 1 1 1 ...

user output
1 2 2 2 1 1 3 1 1 1 1 2 1 3 1 ...

Test 50

Verdict:

input
500 275
636562060 767928734 906523441 ...

correct output
176 215 251 178 254 161 252 12...

user output
(empty)

Test 51

Verdict:

input
500 209
773442532 122816 137572579 324...

correct output
163 1 31 72 37 57 23 89 45 87 ...

user output
(empty)

Test 52

Verdict:

input
500 218
198730372 27838076 590195590 4...

correct output
42 8 130 102 113 97 73 75 34 4...

user output
(empty)

Test 53

Verdict:

input
500 276
75940263 760367935 901888417 3...

correct output
20 205 249 85 32 149 165 267 1...

user output
(empty)

Test 54

Verdict:

input
500 484
967034924 587586158 185430194 ...

correct output
469 290 97 438 372 322 367 317...

user output
(empty)

Test 55

Verdict:

input
500 111
59249204 934941692 892631472 2...

correct output
5 104 100 24 42 109 55 9 70 46...

user output
(empty)

Test 56

Verdict:

input
500 447
356460601 224848374 881788059 ...

correct output
154 88 394 30 18 168 46 279 43...

user output
(empty)

Test 57

Verdict:

input
500 39
244103474 837431431 342493822 ...

correct output
9 33 13 18 31 19 13 23 11 21 3...

user output
(empty)

Test 58

Verdict:

input
500 437
11934038 257096283 933290530 4...

correct output
7 101 407 167 251 388 97 191 7...

user output
(empty)

Test 59

Verdict:

input
500 6
391337048 538883744 535937150 ...

correct output
3 4 4 4 1 2 3 2 1 2 6 3 2 2 2 ...

user output
(empty)