| Task: | Lista |
| Sender: | Yytsi |
| Submission time: | 2025-11-09 11:15:50 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.00 s | details |
| #3 | ACCEPTED | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m; cin>>n>>m;
vector<int> reqs(m);
for (int i = 0; i < m; i++) cin>>reqs[i];
sort(reqs.begin(), reqs.end());
vector<pair<int, int>> batches;
for (int i = 0, j = 0; i < m; i = j) {
while (j < m && reqs[i] == reqs[j]) j++;
batches.push_back({j - i, reqs[i]});
}
sort(batches.begin(), batches.end());
reverse(batches.begin(), batches.end());
vector<int> nums;
int ans = 0, curidx = 1;
for (auto [cnt, v] : batches) {
ans += cnt * curidx;
curidx++;
nums.push_back(v);
}
for (int i = 1; i <= n; i++) {
bool f = false;
for (int v : nums) f |= v == i;
if (!f) nums.push_back(i);
}
cout << ans << "\n";
for (int v : nums) cout << v << " ";
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 1 1 1 |
| correct output |
|---|
| 1 1 |
| user output |
|---|
| 1 1 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 100 1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 1000 1 100 99 98 97 96 95 94 93 92 ... |
| user output |
|---|
| 1000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 100 1000 1 2 2 2 1 1 1 1 1 1 1 1 1 2 1 ... |
| correct output |
|---|
| 1488 1 2 100 99 98 97 96 95 94 93 9... |
| user output |
|---|
| 1488 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 100 1000 7 8 2 4 8 3 3 10 9 7 7 6 8 7 2... |
| correct output |
|---|
| 5109 3 8 7 5 1 6 2 4 9 10 100 99 98... |
| user output |
|---|
| 5109 3 8 7 5 1 6 2 4 9 10 11 12 13 ... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 100 1000 23 85 3 99 63 79 38 37 67 28 7... |
| correct output |
|---|
| 41714 57 38 63 62 93 85 95 81 79 61 ... |
| user output |
|---|
| 41714 57 38 63 62 93 85 95 81 79 61 ... |
