智力大冲浪

 

传送门:https://www.luogu.org/problemnew/show/P1230

首先解释一下题意,所谓的时间段指的是[1~这个数字]内的任意个整数都可以做游戏,花费1时间。

很明显这是一道贪心题,为了使得的钱尽可能多,就要使扣的钱尽可能少,因此要先安排扣钱多的游戏。

又为了尽量给后面的游戏让地方,先安排的游戏要尽量选择尽可能靠后的时间。

代码

#include<cstdio>
#include<algorithm> 
using namespace std;
inline int read(){
    static char ch;
    while((ch = getchar()) < '0' || ch > '9');
    int ret = ch - 48;
    while((ch = getchar()) >= '0' && ch <= '9')
        ret = ret * 10 + ch - 48;
    return ret;
}
int m,n,sum;
bool flag,b[505];
struct node{
    int a,b;
}t[505];
bool cmp(node x,node y){return x.b > y.b;}
int main(){
    m = read();
    n = read();
    for(int i = 1;i <= n;i++) t[i].a = read();
    for(int i = 1;i <= n;i++) t[i].b = read();
    for(int i = 1;i <= n;i++) b[i] = true;
    sort(t+1,t+n+1,cmp);
    for(int i = 1;i <= n;i++){
        flag = false;
        for(int j = t[i].a;j >= 1;j--){
            if(b[j]){
                b[j] = 0;
                flag = true;
                break;
            }
        }
        if(!flag) sum += t[i].b;
    }
    printf("%d",m - sum);
    return 0;
}

 

posted @ 2018-10-29 15:06  我的露娜不会飘  阅读(114)  评论(0编辑  收藏  举报