链接:

https://codeforces.com/contest/1271/problem/D

题意:

You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer n castles of your opponent.

Let's describe the game process in detail. Initially you control an army of k warriors. Your enemy controls n castles; to conquer the i-th castle, you need at least ai warriors (you are so good at this game that you don't lose any warriors while taking over a castle, so your army stays the same after the fight). After you take control over a castle, you recruit new warriors into your army — formally, after you capture the i-th castle, bi warriors join your army. Furthermore, after capturing a castle (or later) you can defend it: if you leave at least one warrior in a castle, this castle is considered defended. Each castle has an importance parameter ci, and your total score is the sum of importance values over all defended castles. There are two ways to defend a castle:

if you are currently in the castle i, you may leave one warrior to defend castle i;

there are m one-way portals connecting the castles. Each portal is characterised by two numbers of castles u and v (for each portal holds u>v). A portal can be used as follows: if you are currently in the castle u, you may send one warrior to defend castle v.

Obviously, when you order your warrior to defend some castle, he leaves your army.

You capture the castles in fixed order: you have to capture the first one, then the second one, and so on. After you capture the castle i (but only before capturing castle i+1) you may recruit new warriors from castle i, leave a warrior to defend castle i, and use any number of portals leading from castle i to other castles having smaller numbers. As soon as you capture the next castle, these actions for castle i won't be available to you.

If, during some moment in the game, you don't have enough warriors to capture the next castle, you lose. Your goal is to maximize the sum of importance values over all defended castles (note that you may hire new warriors in the last castle, defend it and use portals leading from it even after you capture it — your score will be calculated afterwards).

Can you determine an optimal strategy of capturing and defending the castles?

思路:

计算到每个城堡最少多少人,计算出每个位置可以派出去多少人。

记录每个点最右边的坐标,因为左边的人可以带到右边去用,所以往右边放是较优的。

这样就可以用一个堆来维护。

代码:

#include<bits/stdc++.h>
using namespace std; const int MAXN = 5e3+10; struct Node
{
int v, i;
bool operator < (const Node & rhs) const
{
return this->v < rhs.v;
}
}; priority_queue<Node> que;
int a[MAXN], b[MAXN], c[MAXN];
int need[MAXN], las[MAXN], use[MAXN];
int n, m, k; int main()
{
cin >> n >> m >> k;
for (int i = 1;i <= n;i++)
cin >> a[i] >> b[i] >> c[i], las[i] = i;
int u, v;
for (int i = 1;i <= m;i++)
{
cin >> u >> v;
las[v] = max(las[v], u);
}
need[n] = a[n];
for (int i = n-1;i >= 1;i--)
need[i] = max(a[i], need[i+1]-b[i]);
int sum = k;
for (int i = 1;i <= n;i++)
{
if (sum < a[i])
{
puts("-1");
return 0;
}
sum += b[i];
}
sum = k;
for (int i = 1;i <= n;i++)
{
use[i] = sum+b[i]-need[i+1];
sum = need[i+1];
que.push(Node{c[i], i});
}
int ans = 0;
while(!que.empty())
{
int val = que.top().v;
int x = que.top().i;
que.pop();
int y = las[x];
while(use[y] == 0 && y > 0)
y--;
if (y == 0)
continue;
use[y]--;
ans += val;
}
cout << ans << endl; return 0;
}

最新文章

  1. pip安装MySQL-python报错
  2. Javascript 语言精粹 代码片段合集
  3. Java 中文字符串编码之GBK转UTF-8
  4. tomcat缓存静态资源深入
  5. 浅谈ES5的const以及strict mode
  6. innobackupex 恢复实验
  7. Centos 6.2 32位机器安装新的JDK和Weblogic
  8. 定时关机命令——shutdown
  9. linux下利用curl监控web应用状态
  10. 微信小程序,前端大梦想(四)
  11. Java基本语法-----java注释
  12. centos docker 升级至最新稳定版--摘自官网
  13. OOCSS(面向对象的CSS)总结
  14. vue项目首次加载过慢
  15. calc_load
  16. Java多线程及线程状态转换
  17. yii框架的部署方法
  18. tensorflow的升级与版本管理
  19. Laravel 跨框架队列交互
  20. Python学习-12.Python的输入输出

热门文章

  1. limit和offset、切片操作
  2. PHP xdebug 断点调试
  3. MSF魔鬼训练营-3.3.2 口令猜测与嗅探
  4. hdfs基本文件操作
  5. Eureka注册中心
  6. mysql的索引为什么要使用B+树而不是其他树?
  7. O019、通过例子学习 Keystone
  8. java apache-commons-collections中Map辅助类的使用
  9. textarea 限制输入字数
  10. 解决GitHub添加sshkey仍然无法访问clone远程仓库的问题