F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Harry Potter and the Polyjuice Potion

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 665    Accepted Submission(s): 165


Problem Description
Polyjuice potion is one of the most famous magic medicines in Harry Porter which had been made by our talented witch Hermione Jean Granger when she was a little girl. But at the very beginning, she didn't know the prescription, so she had to try several materials to make it up. After that, she found there were only twenty materials which could possibly make the polyjuice potion. And she also noticed that some combination of the materials of the twenty materials will get an effect Ei(-1000 < Ei < 1000).If she choose a subset S of the materials, the final effect will be the sum of effect values of all combinations appeared in S. Because Hermione is very clever, she calculated all the effect value of the combinations. So what's the maximum effect value the polyjuice potion will get?

 

Input
Input contains multiple test cases(at most 10).
For each test case, the first line contains a positive integer N(N <= 100000) indicate the number of the combinations.
Then N lines follow, each line contains two number c (0 <= c < 2^20), v(-1000 < v < 1000),indicate the effect value of the combination c (binary representation).
Input ends with a negtive number.

 

Output
For each test case output a number indicates the maximum value of the polyjuice potion.
 

Sample Input
3 1 9 2 -10 3 300 -1
 

Sample Output
299
 

Author
fatboy_cw@WHU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-07 09:23:44, Gzip enabled