1. Description of the problem
Xiao Wei enrolled in a television station's intelligence big Surfing program, this challenge has attracted many contestants, the host in order to honor everyone's courage, first reward each contestant M yuan. Don't be happy too early, 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), the game gives a lot of small games, each game must be within the specified deadline $t _1$ completed (1 <= $t _1$ <= N). If a game can not be completed within the stipulated period, then to deduct from the reward fee m part of the money $w _i$, $w _i$ for the natural number, different games deducted money is not the same. Of course, each game itself is simple enough to ensure that each contestant is able to complete within a single period of time and must start with an integer period. The host just wants to test how each contestant arranges their own game order. As a contestant, Xiao Wei wants to win the championship and, of course, wants to win the most money.
2. Input format
Input Total 4 rows
The first act, M, represents the first reward for each contestant's money
The second behavior n, indicates that there are n small games
The third line has n number, respectively, the game 1 to n the specified completion period
The number of n in line four indicates the amount of the deduction that the game 1 to n cannot complete within the stipulated period.
3. Output format
The output is only one line, which means the most money that Xiao Wei can earn
4. Sample input
10000 7 4 2 4 3 1 4 6 - - - + - - Ten
5. Sample Output
9950
6. Analysis of Ideas
According to the amount of the deduction from the big to the small sort, the order processing each task, so that it as far as possible to arrange, if not arranged, then select the deduction
7. Code (the title of the data by default in descending order, so I do not sort of)
#include <iostream>#include<cstring>using namespacestd;intM,n;intdate[505],money[505],arrange[505];intSolve (intTime );intMain () {Ios::sync_with_stdio (false); CIN>>m>>N; memset (Arrange,-1,sizeof(arrange)); inti =1; for(; I <= n;i++) Cin>>Date[i]; for(i =1; I <= n;i++) Cin>>Money[i]; for(i =1; I <= n;i++) { intK =Solve (Date[i]); if(k! =-1) Continue; Elsem-=Money[i]; } cout<<m; return 0;}intSolve (intTime ) { inti =Time ; while(I >=1) { if(Arrange[i] = =-1) {Arrange[i]=1; time=i; returnTime ; } ElseI--; } return-1;}
Greedy algorithm Training (eight)--Intelligence Big surf (unit time scheduling problem with deadlines and fines)