你在玩金铲铲之战,必须打倒敌人以强化自己的战斗力。这个游戏中有若干个 boss,你把所有boss 全部打败即完成游戏。打boss 的顺序可以自选。为了让你们计算起来更加轻松,我大大简化了每个 boss的属性,每个 boss只有两项属性:击败它需要的战斗力数值(大于等于该数值即可击败)、击败它之后,你可以永久获得的战斗力增加数值。在游戏的开始,你可以获得一定的战斗力,且这个战斗力与你花的钱成正比。你当然想尽可能地省钱,因此请你计算出能够通关的的前提下,一开始获得的最小战斗力。
#include <iostream>
#include <map>
using namespace std;
int main()
{
int n = 0;
cin >> n;
multimap<int, int> value;
for (int i = 0; i < n; ++i)
{
int a = 0, b = 0;
cin >> a >> b;
value.insert(make_pair(a, b));
}
int res = 0, fight = 0;
for (auto boss : value)
{
if (boss.first > fight)
{
int temp = boss.first - fight;
res += temp;
fight += temp;
}
fight += boss.second;
}
cout << res << endl;
return 0;
}