如果没有必选的限制条件,就是水题了、、、

只要按照w + t排序就可以了,然后搞个堆来维护

于是有了限制条件,还是水题。。。

到了必选的时候强制选上,不加入堆中即可。

 /**************************************************************
Problem: 1555
User: rausen
Language: C++
Result: Accepted
Time:2228 ms
Memory:10948 kb
****************************************************************/ #include <cstdio>
#include <cctype>
#include <algorithm>
#include <queue> using namespace std;
typedef long long ll;
const int N = ; struct data {
int w, t, f;
}a[N];
bool operator < (const data &a, const data &b) {
return (ll) a.w + a.t < (ll) b.w + b.t;
} ll tot, V;
int n, m, w, ans;
priority_queue <int> q; inline ll read() {
ll x = ;
char ch = getchar();
while (!isdigit(ch))
ch = getchar();
while (isdigit(ch)) {
x = x * + ch - '';
ch = getchar();
}
return x;
} inline void del_top() {
tot -= q.top(), q.pop();
--ans;
} inline void add(int x) {
tot += a[x].w, q.push(a[x].w);
++ans;
} bool work() {
int i;
tot = ;
for (i = ; i <= n; ++i)
if (a[i].f == ) {
while (tot > a[i].t) {
if (q.empty()) return ;
del_top();
}
tot += a[i].w, ++ans;
}else {
if (!q.empty() && tot > a[i].t)
if (q.top() < a[i].w || tot - q.top() > a[i].t)
continue;
if (tot > a[i].t)
del_top();
add(i);
}
return ;
} int main() {
int i, X;
n = read(), m = read(), V = read();
for (i = ; i <= n; ++i)
a[i].w = read(), a[i].t = read();
for (i = ; i <= m; ++i) {
X = read(), a[X].f = ;
tot += a[X].w;
}
sort(a + , a + n + );
a[++n].f = , a[n].t = V;
if (!work()) puts("Foolish SD!");
else printf("%d\n", ans - );
return ;
}

(p.s. 怎么又想开fread二笔优化了呢、、、233)

最新文章

  1. linux 配置ssh免密码登陆本机
  2. 获取ip ,百度地图坐标点 和 在 后台调用 url()
  3. freeCAD特性列表
  4. 0001 Oracle数据库安装
  5. AngularJs的UI组件ui-Bootstrap分享(五)——Pager和Pagination
  6. WM_CLOSE WM_DESTROY WM_QUIT的区别
  7. Eclipse插件推荐:UCDetector: Unnecessary Code Detector
  8. Hadoop卸载或增加节点
  9. Centos安装jdk8
  10. 008_ssl Certificate Pinning
  11. angular6 safe url pipe
  12. 学习笔记CB005:关键词、语料提取
  13. go语言学习--go中godep的使用小结
  14. spring框架加载完成后执行上下文刷新事件(ContextRefreshedEvent)
  15. 第七次Scrum冲刺
  16. Sybase 删除表的某列
  17. GetTitleAndUrl
  18. zoj 3157 Weapon 逆序数/树状数组
  19. C++ STL:lower_bound与upper_bound实现
  20. rand7生成rand10,rand1生成rand6,rand2生成rand5(包含了rand2生成rand3)

热门文章

  1. Scala并发编程模型AKKA
  2. Scala数组和集合
  3. 【Python项目篇】【爬妹子图】
  4. JAVA优化技巧分享 让游戏更加的流畅
  5. Flask系列之源码分析(一)
  6. 2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution
  7. 20155207 2016-2017-2 《Java程序设计》第八周学习总结
  8. SQL学习笔记四(补充-1-1)之MySQL单表查询补充部分:SQL逻辑查询语句执行顺序
  9. 20145301赵嘉鑫《网络对抗》逆向及Bof基础
  10. 20162326 qilifeng 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1