CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » November Long Contest 2011 » Stepping Average

Stepping Average

Problem code: STEPAVG

  • All Submissions

All submissions for this problem are available.

Consider the following weird way of finding the average of N numbers. Take any two of the numbers and replace them with their average; repeat this operation exactly N-1 times. The only remaining number is called the stepping average of the initial set. Note that a set may obviously have different stepping averages depending on our choice for every operation.

Your task is, given N integers, find a way of performing the operations such that the resulting stepping average is as close to the given integer K as possible. Note that this is a challenge problem: you don't have to find the best possible solution, but the better is your solution the more points you get.

Input

The first line of the input contains an integer T -- the number of test cases (no more than 10). Each test case consists of two lines -- the first of them contains two positive integers N and K (N ? 1000, K ? 109), the second contains N space-separated positive integers A1..AN (Ai ? 109).

Output

The output for each test case should contain exactly N-1 pairs of integers. i-th pair (1-based) x y means that numbers Ax and Ay are chosen at the corresponding operation, their average is written to AN+i, and Ax and Ay can't be used any more. See example explanation for more clarity.

Scoring

Your score for each test case is just the absolute difference between K and your remaining number. Your final score is the average of all test case scores. Your goal is to minimize the final score.

Note that in order for your submission not to be judged as 'Wrong Answer' the following conditions should be satisfied:

  • your output should contain exactly N-1 pairs of positive integers separated by at least one space for each test case and nothing else;
  • your output should contain integers strictly less that N+i in the i-th pair (1-based) for each test case;
  • all integers in your output for each test case should be different.

Example

Input:
1
5 5
9 1 6 3 4

Output:
5 2
4 6
3 1
7 8

Explanation:

We have 5 integers here: 9 1 6 3 4. The first operation is 5 2, so the 6th number becomes (4+1)/2 = 2.5, and the 2nd and the 5th numbers are removed, so we have 9 x 6 3 x 2.5 now (here x means a removed number). Then, 4 6 means that the 7th number becomes (3+2.5)/2 = 2.75, and the 4th and the 6th numbers are removed, resulting in 9 x 6 x x x 2.75. Then, after 3 1 we get x x x x x x 2.75 7.5, and after 7 8 we get x x x x x x x x 5.125. The only number left after the operations is 5.125, so your score for the test case is 0.125.

Test Case Generation

Every official input file contains exactly 10 test cases. In every test case N is equal to 1000, K is chosen randomly and uniformly between 1 and 109, and all Ai are chosen randomly and uniformly between 1 and 109 as well.


Author: gennady.korotkevich
Date Added: 30-09-2011
Time Limit: 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

I'm assuming if I submit a

prakhargahlot @ 1 Nov 2011 10:25 PM
I'm assuming if I submit a better answer on the second submission, my previous score will be discarded (Please correct me if I'm wrong). What happens, however, when my later submission(s) fetch lower score than my previous one(s)?

Cant even define an array of

theicebreaker @ 1 Nov 2011 11:09 PM
Cant even define an array of the required size?? int A[1000000000]; does not work. Am I missing something.

Cant even define an array of

theicebreaker @ 1 Nov 2011 11:20 PM
Cant even define an array of the required size?? int A[1000000000]; does not work. Am I missing something.

Here we have an array of 1000

genyaz @ 2 Nov 2011 12:14 AM
Here we have an array of 1000 elements, so you should use int A[1000].

@prakhargahlot: Your real

gennady_adm @ 2 Nov 2011 12:37 AM
@prakhargahlot: Your real score is always the best score among your submissions.

@theicebreaker::Define it

ritesh_gupta @ 2 Nov 2011 01:21 AM
@theicebreaker::Define it globally as stack size is limited

your output should contain

pankajb64 @ 2 Nov 2011 04:13 AM
your output should contain integers strictly less that N+i in the i-th pair (1-based) for each test case I did not understand the meaning. pls explain.

Can I use the random module

sanketsaurav @ 2 Nov 2011 07:38 PM
Can I use the random module in Python 3.1.2? 'Coz when I import the module, it gives a compilation error.

can n be 0 or 1.If yes then

phantom11 @ 3 Nov 2011 12:04 AM
can n be 0 or 1.If yes then what should be the output

@phantom11 "Every official

EgorK @ 3 Nov 2011 01:50 PM
@phantom11 "Every official input file contains exactly 10 test cases. In every test case N is equal to 1000"

for n=0 or 1 , No output will

chhabraamit @ 3 Nov 2011 01:59 PM
for n=0 or 1 , No output will be there.

@bravo_g7: Quite unpleasant!!

rajneesh2k10 @ 6 Nov 2011 11:09 AM
@bravo_g7: Quite unpleasant!! If you don't like the problem, leave it and try some other one. You shouldn't use such filthy language for such a nice community. Ever browsed the problem archives?? Ever thought how many are benefited everyday? Please don't hurt us, the codechef followers. Also maintain dignity of the institute, you are a part of. And yes, computer science and mathematics goes side by side. You can't really be a good algorist without being a good mathematician. Since I don't have a good mathematics so I know its importance. Hope not to see to many of your kind on this community.

@admin: Please delete my

rajneesh2k10 @ 6 Nov 2011 11:14 AM
@admin: Please delete my above comment since now its of no relevance. :)

someone please

big_d @ 7 Nov 2011 12:15 AM
someone please help!!!!!! what does this mean??? "your output should contain integers strictly less that N+i in the i-th pair (1-based) for each test case;" ?????

okay chuck that

big_d @ 7 Nov 2011 12:51 AM
okay chuck that question!!!!! is it a compulsion that my final answer needs to be nearer to k????

How do I get to know score

imdeepakg @ 7 Nov 2011 11:38 PM
How do I get to know score obtained for a submission?

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com