CSES - Putka Open 2015 – 3/6 - Results
Submission details
Task:Kasat
Sender:
Submission time:2015-09-11 23:55:20 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.44 s1details
#20.51 s2details
#30.00 s3details

Code

//package putka.pkg3.pkg1;

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author Adreno
 */
public class Putka31 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        long[] abc = new long[3];
        for (int i=0; i<t; i++) {
            abc[0] = input.nextLong();
            abc[1] = input.nextLong();
            abc[2] = input.nextLong();
            long n = input.nextLong();
            System.out.println(pelaa(abc, n));
        }
    }

    private static String pelaa(long[] abc, long n) {
        while (n > 0) {
            sort(abc);
            System.out.println(Arrays.toString(abc));
            if (abc[0] == abc[1] && abc[1] >= (abc[2] - 1)) break;
            if ((abc[0]+1) >= abc[1] && abc[1] == abc[2]) break;
            long moves = Math.min(abc[2] - abc[0], abc[2] - abc[1]);
            moves = Math.min(abc[1] - abc[0], moves);
            moves = Math.min(n, moves);
            if (moves > 0) {
                abc[0] = abc[0] += moves;
                abc[2] = abc[2] -= moves;
            } else {
                abc[0]++;
                abc[2]--;
                moves = 1;
//                long diff = abc[2] - abc[0];
//                if (abc[1] == abc[0]) {
//                    // case 338
//                    abc[2] -= 2;
//                    abc[1]++;
//                    abc[0]++;
//                    moves = 2;
//                } else {
//                    // case 388
//                    abc[2]--;
//                    abc[1]--;
//                    abc[0] += 2;
//                    moves = 2;
//                }
            }
            n -= moves;
        }
        
        // a==b==c
        if (abc[0] == abc[1] && abc[1] == abc[2]) {
            if (n % 2 != 0) {
                abc[0]++;
                abc[2]--;
                sort(abc);
            }
            return abc[0] + " " + abc[1] + " " + abc[2];
        }
        // a==b==(c-1)
        sort(abc);
        return abc[0] + " " + abc[1] + " " + abc[2];
    }
    
    private static void sort(long[] t) {
        Arrays.sort(t);
        if (1 == 1) return;
        
        if (t[1] < t[0]) {
            long apu = t[0];
            t[0] = t[1];
            t[1] = apu;
        }
        if (t[2] < t[1]) {
            long apu = t[1];
            t[1] = t[2];
            t[2] = apu;
        }
        if (t[1] < t[0]) {
            long apu = t[0];
            t[0] = t[1];
            t[1] = apu;
        }
    }
    
    
}

Test details

Test 1

Group: 1

Verdict:

input
1000
7 69 64 45
37 5 30 81
50 49 37 38
46 37 100 6
...

correct output
46 47 47
24 24 24
45 45 46
43 46 94
32 32 33
...

user output
[7, 64, 69]
[12, 64, 64]
[13, 63, 64]
[14, 63, 63]
[15, 62, 63]
...

Test 2

Group: 2

Verdict:

input
1000
19 13 88 978977859
67 57 39 960003440
81 16 67 971611942
92 96 2 957979201
...

correct output
39 40 41
54 54 55
54 55 55
63 63 64
36 37 38
...

user output
[13, 19, 88]
[19, 19, 82]
[19, 20, 81]
[20, 20, 80]
[20, 21, 79]
...

Test 3

Group: 3

Verdict:

input
1000
211358104 753479603 549127067 ...

correct output
504654924 504654925 504654925
589019272 589019272 589019273
101309993 101309994 101309994
436205296 436205297 436205298
351062567 351062568 351062568
...

user output
(empty)