Under construction

Still being built. Things may change

Making the Best Team

Interview

Time limit1sMemory limit128 MB

Summary
Choose 15 players for white and 15 for black from a list of up to 1000 players to maximize the total ability sum.
Level

Medium5 of 10

Topics
Dynamic programming, Greedy, Array
Solved
No attempts yet

Problem

Each year, the Kkung Association forms a 30-player team for a world chess competition. The team must have 15 players assigned to white and 15 players assigned to black. For every player, their white ability and black ability are given as integers from 1 to 100. A player can participate in only one color during the competition, and some players may be left out. The team's total ability is the sum of the white abilities of the players assigned to white plus the black abilities of the players assigned to black. Find the maximum possible total ability.

Input

The input consists of player ability values. Each line contains two integers W and B separated by a space. W is the player's ability when playing white, and B is the player's ability when playing black. The input has at least 30 lines and at most 1000 lines, and should be read until end of file.

Output

Print the maximum total ability among all teams that can be formed.

Examples1

  1. Example 1

    Input
    87 84
    66 78
    86 94
    93 87
    72 100
    78 63
    60 91
    77 64
    77 91
    87 73
    69 62
    80 68
    81 83
    74 63
    86 68
    53 80
    59 73
    68 70
    57 94
    93 62
    74 80
    70 72
    88 85
    75 99
    71 66
    77 64
    81 92
    74 57
    71 63
    82 97
    76 56
    
    Expected output
    2506