同样是一道贪心题。我们能想到,肯定是要做那些扣钱最多的,所以我们先把扣钱的多少拍一下序,之后,我们一定是要把这件事情尽量拖后做的,这样才能保证尽量不影响其他的事件。而如果这个时间已经被占用,那就尽量向前排,实在排不了的丢弃即可。
看一下代码。
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<cmath> #include<set> #include<queue> #define rep(i,a,n) for(int i = a;i <= n;i++) #define per(i,n,a) for(int i = n;i >= a;i--) #define enter putchar(' ') using namespace std; typedef long long ll; const int M = 200005; const int N = 1005; const int INF = 2147483647; int read() { int ans = 0,op = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') op = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { ans *= 10; ans += ch - '0'; ch = getchar(); } return ans * op; } struct mission { int val,tim; bool operator < (const mission &g) const { return val > g.val; } }a[M]; int sum,n; bool vis[M]; int main() { sum = read(),n = read(); rep(i,1,n) a[i].tim = read(); rep(i,1,n) a[i].val = read(); sort(a+1,a+1+n); rep(i,1,n) per(j,a[i].tim,1) { if(!vis[j]) { vis[j] = 1,a[i].val = 0; break; } } rep(i,1,n) sum -= a[i].val; printf("%d ",sum); return 0; }