Codeforces 479B. Towers c-exams "Sort"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.