| Task: | Kulut |
| Sender: | Septicuss |
| Submission time: | 2023-01-21 13:45:52 +0200 |
| Language: | Java |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.16 s | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | ACCEPTED | 0.17 s | details |
| #5 | ACCEPTED | 0.17 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | ACCEPTED | 0.17 s | details |
| #9 | ACCEPTED | 0.16 s | details |
| #10 | RUNTIME ERROR | 0.07 s | details |
| #11 | TIME LIMIT EXCEEDED | -- | details |
Code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class A {
final static FastReader reader = new FastReader();
final static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) {
int n = reader.nextInt();
int[] payments = new int[n];
int total = 0;
Arrays.fill(payments,0);
for (int i = 0; i < n; i++) {
String name = reader.next();
int cost = reader.nextInt();
int idx = name.charAt(0) - 'A';
payments[idx] += cost;
total += cost;
}
reader.close();
int balanced = total / 4;
for (int i = 0; i < payments.length; i++) {
payments[i] = payments[i] - balanced;
}
int i = 0;
int k = 0;
List<String> tapahtumat = new ArrayList<>();
while (k != 3 ) {
if (payments[i] < 0) {
for (int j = 0; j < payments.length; j++) {
if (i == j) continue;
if (payments[j] == 0) continue;
if (payments[j] < 0) continue;
int giving = payments[i];
int requesting = payments[j];
if (requesting + giving > 0) { // Payer can give more than is asked
payments[j] = 0;
payments[i] += requesting;
tapahtumat.add((char)('A' + i) + " " + (char)('A' + j) + " " + (requesting));
k++;
} else { // Payer can give less than is asked
payments[i] += requesting;
payments[j] += giving;
if (payments[i] == 0) {
k++;
tapahtumat.add((char)('A' + i) + " " + (char)('A' + j) + " " + (Math.abs(giving)));
}
}
}
}
i++;
if (i == 4)
i = 0;
}
writer.println(tapahtumat.size());
for (var s : tapahtumat)
writer.println(s);
writer.flush();
writer.close();
}
static class FastReader {
BufferedReader reader;
StringTokenizer tokenizer;
public FastReader() {
this.reader = new BufferedReader(new InputStreamReader(System.in));
this.tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (Exception e) {
}
}
return tokenizer.nextToken();
}
String nextLine() {
try {
return reader.readLine();
} catch (IOException ex) {
}
return null;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
BigInteger nextBigInt() {
return new BigInteger(next());
}
void close(){
try {
reader.close();
} catch (IOException ex) {
Logger.getLogger(A.class.getName()).log(Level.SEVERE, null, ex);
}
reader = null;
tokenizer = null;
}
}
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 100 C 224 D 4 D 624 D 64 ... |
| correct output |
|---|
| 3 A B 630 C B 1636 C D 1470 |
| user output |
|---|
| 3 A B 2266 A D 1470 C A 3106 |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 D 768 B 608 A 116 C 80 ... |
| correct output |
|---|
| 3 B A 756 B C 1668 D C 1776 |
| user output |
|---|
| (empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 B 184 C 840 D 648 A 876 ... |
| correct output |
|---|
| 3 A B 1131 B C 190 C D 297 |
| user output |
|---|
| (empty) |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 100 C 560 D 664 D 632 C 944 ... |
| correct output |
|---|
| 3 B A 3230 C B 2572 D C 1594 |
| user output |
|---|
| 3 B A 3230 C B 2572 D C 1594 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 100 B 20 A 664 D 504 A 248 ... |
| correct output |
|---|
| 3 A B 138 B C 652 C D 350 |
| user output |
|---|
| 3 A C 302 A D 350 B A 514 |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 B 204 D 520 C 500 C 256 ... |
| correct output |
|---|
| 3 B A 285 B C 482 C D 1321 |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 B 672 B 840 A 712 C 640 ... |
| correct output |
|---|
| 3 B A 324 C B 5128 D C 2920 |
| user output |
|---|
| (empty) |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 100 C 860 D 732 A 952 C 940 ... |
| correct output |
|---|
| 3 A B 24 C B 536 D C 2252 |
| user output |
|---|
| 3 A B 560 A C 1716 D A 2252 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 100 C 84 A 592 B 840 C 708 ... |
| correct output |
|---|
| 3 A B 115 B C 1746 D C 3791 |
| user output |
|---|
| 3 A C 5537 B A 5422 D B 3791 |
Test 10
Verdict: RUNTIME ERROR
| input |
|---|
| 1 A 100 |
| correct output |
|---|
| 3 B A 75 C B 50 D C 25 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds...
Test 11
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 4 A 25 B 25 C 25 D 25 |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
