Title: Codeforces 479B. Towers
Test instructions: Give a sequence of length n, up to a maximum of k operations, select one of the largest minus 1, the smallest plus 1, and then ask the minimum difference after the maximum number of k operations.
Very simple, practice python syntax
N,k = Map (Int,raw_input (). Split ()) L = map (Int,raw_input (). Split ()) ans = []i = 0while i<k: if (max (L)-min (l) >0) : #取最大值 A, B = L.index (max (L)), L.index (min (l)) #最大值的位置 l[a]-=1 l[b]+=1 i+=1 ans.append ([a+1,b+1 ]) else: breakprint max (l)-min (L), Len (ans) for i in ans: print i[0],i[1]
By the way, a simple sort of code for the C question:
n = input () L = []for i in Range (n): A, b = Map (Int,raw_input (). Split ()) l.append ([A, b]) L.sort () ans = 0for I in l:
re = min (i) if Re>=ans:ans = re else: ans = max (i) Print ans
Codeforces 479B. Towers c-exams "Sort"