Intellectual big Surfing (RIDDL) problem
Xiao Wei enrolled in CCTV's intellectual big surfing program. The challenge attracted a lot of contestants, the host to honor everyone's courage, first reward each contestant M yuan. Don't be too happy first! Because the money is not necessarily yours?! Then the host announced the rules of the game:
First of all, the game time is divided into N-period (n≤500), it gives a lot of small games, each small game must be in the stipulated period TI before completion (1≤ti≤n). If a game can not be completed before the deadline, then you have to deduct a portion of the money from the award fee m WI,WI to the natural number, different games deducted the money is not the same. Of course, each game itself is simple enough to ensure that each contestant can be completed within a period of time and must start all the time. The host just wants to test how each contestant arranges to organize their own game order. As a contestant, Xiao Wei wants to win the championship and, of course, wants to win the most money! Note: The competition will never lose money to the contestants.
Input
Total 4 lines:
The 1th act m, which represents the first prize to each contestant's money;
The 2nd Act n, indicates that there are n small games;
The 3rd line has n number, respectively indicates the game 1 to n the stipulation completion period;
The 4th line has n number, respectively, the game 1 to n can not be completed before the specified period of deduction.
Output
Just 1 lines, that Xiao Wei can win the most money.
Sample input
1000074 2 4 3 1 4 670 60 50 40 30 20 10
Sample output
9950
Analytical
We can sort by the amount of money, we can put the game in the order of the specified period, and record it with an array, if there is a game in the specified period, we can put it in front of an empty (until 1~t full).
#include <bits/stdc++.h>using namespacestd;Const intMAXN =502;structTimes {intA, B;};BOOLCMP (times A, times b) {if(A.B = =b.b) {returnA.A <B.A; } returnA.B >b.b;} intMain () {intN, Sum, A[MAXN]; Times S[MAXN]; scanf ("%d%d", &sum, &N); for(inti =0; I < n; i++) {A[i]= -1; scanf ("%d", &s[i].a); S[I].A-=1; } for(inti =0; I < n; i++) {scanf ("%d", &s[i].b); } sort (s, S+N, CMP); intSUM1 =0; for(inti =0; I < n; i++) { intm =s[i].a; while(M >=0) { if(A[m] = =-1) {A[m]=i; Break; } Else if(M >0) {m--; } Else if(M = =0) {sum1+=s[i].b; Break; }}} printf ("%d\n", Sum-sum1); }
View Code
Intelligence Big surf-greedy