CSES - Putka Open 2015 – 3/6 - Results
Submission details
Task:Kasat
Sender:
Submission time:2015-09-12 21:49:46 +0300
Language:Python2
Status:READY
Result:79
Feedback
groupverdictscore
#10
#2ACCEPTED33
#3ACCEPTED46
Test results
testverdicttimegroup
#10.06 s1details
#2ACCEPTED0.07 s2details
#3ACCEPTED0.07 s3details

Code

import sys
import math
import itertools
from collections import defaultdict

#sys.stdin.readline().rstrip()


t = int(sys.stdin.readline().rstrip())
for i in xrange(t):
	nums = map(int, sys.stdin.readline().rstrip().split())
	a,b,c = sorted(nums[:3])
	tot = sum([a,b,c])
	end = [tot//3]*3
	for i in range(tot % 3):
		end[-i] += 1
	n = nums[3]
	#print end, tot, sum([abs(a-end[0]), abs(b-end[1]), abs(c-end[2])]), n//2
	if tot % 3 == 0 and sum([abs(a-end[0]), abs(b-end[1]), abs(c-end[2])])//2 <= n:
		qweqwe = sum([abs(a-end[0]), abs(b-end[1]), abs(c-end[2])])
		n -= qweqwe//2
		a = b = c = tot//3
		if n % 2 == 1:
			print a-1,b,c+1
		else:
			print a,b,c
		continue
	d1 = b-a
	d2 = c-b
	a += min(d1, d2, n)
	c -= min(d1, d2, n)
	n -= min(d1, d2, n)
	d = max(b-a, c-b)
	#print a,b,c,n,int(math.ceil(d*2./3))
	if n > 0 and n < int(math.ceil(d*2./3)):
		if a < b:
			a += n
			if n % 2 == 0:
				b -= n//2
				c -= n//2
			else:
				b -= n//2 - 1
				c -= n//2
		else:
			c -= n
			if n % 2 == 0:
				a += n//2
				b += n//2
			else:
				a += n//2
				b += n//2 + 1
	elif n > 0:
		a = b = c = tot//3
		if tot % 3 == 1:
			c += 1
		if tot % 3 == 2:
			b += 1
			c += 1
	print a,b,c
	'''
			c -= n
		m = res % 3:
		res = [tot//3]*3
		for i in range(m):
			res[i] += 1
	else:

	if a < b:
		a += min(b-a, n)
		n -= min(b-a, n)
	elif c > b:
		a += min(b-a, n)
	d = min(max(b-a, c-b), n)
	'''
	
	
		
	

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
46 47 47
24 24 24
45 45 46
43 46 94
32 32 33
...

Test 2

Group: 2

Verdict: ACCEPTED

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
39 40 41
54 54 55
54 55 55
63 63 64
36 37 38
...

Test 3

Group: 3

Verdict: ACCEPTED

input
1000
211358104 753479603 549127067 ...

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

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