| Task: | Lista |
| Sender: | TapaniS |
| Submission time: | 2025-11-07 20:25:32 +0200 |
| Language: | Java |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.17 s | details |
| #2 | ACCEPTED | 0.18 s | details |
| #3 | ACCEPTED | 0.18 s | details |
| #4 | ACCEPTED | 0.19 s | details |
| #5 | ACCEPTED | 0.19 s | details |
Code
import java.util.*;
public class lista {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] parts = input.nextLine().split(" ");
int n = Integer.parseInt(parts[0]); // koko
int m = Integer.parseInt(parts[1]); // maara
String[] numerot = input.nextLine().split(" "); // numerot
int[] numero = new int[m]; // numerot
int[] counter = new int[n];
int val = 0;
for (int i = 0; i < m; i++) {
val = Integer.parseInt(numerot[i]);
numero[i] = val;
counter[val-1]++;
}
input.close();
// Program here
Integer[] indexes = new Integer[n];
for (int i = 0; i < n; i++) {
indexes[i] = i; // store original index
}
Arrays.sort(indexes, new Comparator<Integer>() {
@Override
public int compare(Integer i1, Integer i2) {
return Integer.compare(counter[i2], counter[i1]); // descending
}
});
int ans = 0;
int pos = 1;
for (int idx : indexes) {
ans += counter[idx] * pos;
pos++;
}
System.out.println(ans);
for (int idx : indexes) {
System.out.print((idx+1) + " ");
}
} // main
}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 1 5 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 38 57 63 62 85 93 12 20 25 26 ... |
