1. 程式人生 > >智力大沖浪

智力大沖浪

show nbsp 沖浪 clu lan ans etc putchar tchar

傳送門

同樣是一道貪心題。我們能想到,肯定是要做那些扣錢最多的,所以我們先把扣錢的多少拍一下序,之後,我們一定是要把這件事情盡量拖後做的,這樣才能保證盡量不影響其他的事件。而如果這個時間已經被占用,那就盡量向前排,實在排不了的丟棄即可。

看一下代碼。

#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(‘\n‘) 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\n",sum); return 0; }

智力大沖浪