标签:
Supermarket Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
4 50 2 10 1 20 2 30 1 7 20 1 2 1 10 3 100 2 8 2 5 20 50 10
Sample Output
80 185
Hint
#include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define N 100005 int f[N]; struct point { int p, d; }P[N]; bool cmp(point a, point b) { return a.p > b.p; } int found(int x) { if(f[x] == -1) return x; return f[x] = found(f[x]); } int main() { int n; while(cin >> n) { memset(f, -1, sizeof(f)); for(int i = 0; i < n; i++) cin >> P[i].p >> P[i].d; sort(P, P+n, cmp); int sum = 0; for(int j = 0; j < n; j++) { int t = found(P[j].d); // 寻找这个时间点之前最晚哪一天没有卖东西 if(t > 0) // 如果时间==0,说明这个东西限制天数之前都已经卖出去比它还值钱的东西了,这个东西profit就得不到 { sum += P[j].p; f[t] = t-1; // 如果这个东西可以卖出去,就把它根节点置为前一天,说明前一天还可以卖东西,这一天不能再卖了 } } cout << sum << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/Tinamei/p/4678070.html