如果没有必选的限制条件,就是水题了、、、
只要按照w + t排序就可以了,然后搞个堆来维护
于是有了限制条件,还是水题。。。
到了必选的时候强制选上,不加入堆中即可。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /************************************************************** 2 Problem: 1555 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:2228 ms 7 Memory:10948 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <cctype> 12 #include <algorithm> 13 #include <queue> 14 15 using namespace std; 16 typedef long long ll; 17 const int N = 600005; 18 19 struct data { 20 int w, t, f; 21 }a[N]; 22 bool operator < (const data &a, const data &b) { 23 return (ll) a.w + a.t < (ll) b.w + b.t; 24 } 25 26 ll tot, V; 27 int n, m, w, ans; 28 priority_queue <int> q; 29 30 inline ll read() { 31 ll x = 0; 32 char ch = getchar(); 33 while (!isdigit(ch)) 34 ch = getchar(); 35 while (isdigit(ch)) { 36 x = x * 10 + ch - '0'; 37 ch = getchar(); 38 } 39 return x; 40 } 41 42 inline void del_top() { 43 tot -= q.top(), q.pop(); 44 --ans; 45 } 46 47 inline void add(int x) { 48 tot += a[x].w, q.push(a[x].w); 49 ++ans; 50 } 51 52 bool work() { 53 int i; 54 tot = 0; 55 for (i = 1; i <= n; ++i) 56 if (a[i].f == 1) { 57 while (tot > a[i].t) { 58 if (q.empty()) return 0; 59 del_top(); 60 } 61 tot += a[i].w, ++ans; 62 }else { 63 if (!q.empty() && tot > a[i].t) 64 if (q.top() < a[i].w || tot - q.top() > a[i].t) 65 continue; 66 if (tot > a[i].t) 67 del_top(); 68 add(i); 69 } 70 return 1; 71 } 72 73 int main() { 74 int i, X; 75 n = read(), m = read(), V = read(); 76 for (i = 1; i <= n; ++i) 77 a[i].w = read(), a[i].t = read(); 78 for (i = 1; i <= m; ++i) { 79 X = read(), a[X].f = 1; 80 tot += a[X].w; 81 } 82 sort(a + 1, a + n + 1); 83 a[++n].f = 1, a[n].t = V; 84 if (!work()) puts("Foolish SD!"); 85 else printf("%d\n", ans - 1); 86 return 0; 87 }
(p.s. 怎么又想开fread二笔优化了呢、、、233)
By Xs酱~ 转载请说明
博客地址:http://www.cnblogs.com/rausen