Zoj 3657 the little girl who picks mushrooms 37th ACM/ICPC Changchun Division Field competition question C (water question)

Source: Internet
Author: User
The little girl who picks mushrooms
Time limit:2 seconds Memory limit:32768 KB

It's yet another festival season in gensokyo. little girl Alice planned to pick mushrooms in five mountains. she brought five bags with her and used different bags to collect mushrooms from different mountains. each bag has a capacity of 2012 grams. alice has finished picking mushrooms in 0 ≤N≤ 5 mountains. InI-Th Mountain, she picked 0 ≤WiLess than or equal to 2012 grams of mushrooms. now she is moving forward to the remained mountains. after finishing picking mushrooms in all the five mountains, she want to bring as much mushrooms as possible home to cook a delicious soup.

Alice lives in the forest of magic. at the entry of the forest of magic, lives three mischievous fairies, sunny, lunar and star. on Alice's way back home, to enter the forest, she must give them exactly three bags of mushrooms whose total weight must be of integral kilograms. if she cannot do so, she must leave all the five bags and enter the forest with no mushrooms.

Somewhere in the forest of magic near Alice's house, lives a magician, Marisa. Marisa will steal 1 kilogram of mushrooms repeatedly from Alice until she has no more than 1 kilogram mushrooms in total.

So when Alice get home, what's the maximum possible amount of mushrooms Alice has? Remember that our common sense doesn't always hold in gensow.people in gensow.belive that 1 kilograms is equal to 1024 grams.

Input

There are about 8192 test cases. process to the end of file.

The first line of each test case contains an integer 0 ≤N≤ 5, the number of mountains where Alice has picked mushrooms. The second line containsNIntegers 0 ≤Wi≤ 2012, the amount of mushrooms picked in each mountain.

Output

For each test case, output the maximum possible amount of mushrooms Alice can bring home, modulo 20121014 (this isNotA prime ).

Sample Input
 
194512 512 512 5125100 200 300 400 5005208 308 508 708 1108
Sample output
 
102410240792
Note

In the second sample, if Alice doesn't pick any mushrooms from the 5-th Mountain. she can give (512 + 512 + 0) = 1024 grams of mushrooms to sunny, lunar and star. marisa won't steal any mushrooms from her as she has exactly 1 kilograms of mushrooms in total.

In the third sample, there are no three bags whose total weight is of integral kilograms. So Alice must leave all the five bags and enter the forest with no mushrooms.

In the last sample:

    • Giving sunny, lunar and Star: (208 + 308 + 508) = 1024
    • Stolen by Marisa: (708 + 1108)-1024) = 792

 

This question is more difficult... I didn't understand the meaning of the question at the beginning, and I don't know how the first example came from ....

Incorrect understanding.

During the on-site competition, I first performed K and then completed B. Teammates can't understand this question all the time.

Then I will look at this c question again... I read the question several times again. . It turned out to be five mountains, but now only N mountains have been completed.

Then I quickly wrote this question ..... This is the title of AC after the seal... As a result, there is no time to do other questions... Cup.

 

When N = 1024, the answer is, which is very simple.

When n = 5, enumerate three, let the sum of the three values be a multiple of 1024, And then solve the maximum value.

N = 4:

First, we need to enumerate three. Check if there are any three that are multiples of 1024. If there is an answer, it will be 1024... (It is estimated that many teams are not doing this ).

Then enumerate the two values to find the maximum value.

 

 

# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Include <Iostream> Using  Namespace  STD;  Int A [ 6  ];  Int  Main (){  Int  N;  While (Scanf ( "  % D  " , & N )! = EOF ){  Int Sum = 0 ;  For ( Int I = 0 ; I <n; I ++ ) {Scanf (  "  % D  " ,& A [I]); sum + = A [I];}  If (N> = 0 & Amp; n <= 3  ) {Printf ( "  1024 \ n  "  );  Continue  ;}  Int Ans = 0  ;  If (N = 5  ){  For ( Int I = 0 ; I <5 ; I ++ )  For ( Int J = I + 1 ; J < 5 ; J ++ )  For ( Int K = J + 1 ; K < 5 ; K ++ )  If (A [I] + A [J] + A [k]) % 1024 = 0  ){  Int Temp = sum-A [I]-A [J]- A [k];  While (Temp> 1024 ) Temp-= 1024  ;  If (Temp> ans) ans = Temp;} printf (  "  % D \ n  " , ANS );  Continue  ;}  If (N = 4  ) {Ans = 0  ;  For ( Int I = 0 ; I < 4 ; I ++ )  For (Int J = I + 1 ; J < 4 ; J ++ )  For ( Int K = J + 1 ; K < 4 ; K ++ )  If (A [I] + A [J] + A [k]) % 1024 = 0  ) {Ans =1024  ;}  If (ANS> 0  ) {Printf (  "  1024 \ n  "  );  Continue  ;}  For ( Int I = 0 ; I < 4 ; I ++ )  For ( Int J = I + 1 ; J < 4 ; J ++ ){  Int Temp = A [I] + A [J];  While (Temp> 1024 ) Temp-= 1024  ;  If (Temp> ans) ans =Temp;} printf (  "  % D \ n  "  , ANS );  Continue  ;}}  Return   0  ;} 

 

 

 

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.