Codeforces Round #625 Div. 1 Problem C

Problem C - World of Darkraft: Battle for Azathoth

Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.
Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack modifier ai and is worth cai coins, and armor set j has defense modifier bj and is worth cbj coins.
After choosing his equipment Roma can proceed to defeat some monsters. There are p monsters he can try to defeat. Monster k has defense xk, attack yk and possesses zk coins. Roma can defeat a monster if his weapon’s attack modifier is larger than the monster’s defense, and his armor set’s defense modifier is larger than the monster’s attack. That is, a monster k can be defeated with a weapon i and an armor set j if ai>xk and bj>yk. After defeating the monster, Roma takes all the coins from them. During the grind, Roma can defeat as many monsters as he likes. Monsters do not respawn, thus each monster can be defeated at most one.
Thanks to Roma’s excessive donations, we can assume that he has an infinite amount of in-game currency and can afford any of the weapons and armor sets. Still, he wants to maximize the profit of the grind. The profit is defined as the total coins obtained from all defeated monsters minus the cost of his equipment. Note that Roma must purchase a weapon and an armor set even if he can not cover their cost with obtained coins.
Help Roma find the maximum profit of the grind.
Input
The first line contains three integers n, m, and p (1≤n,m,p≤2⋅105) — the number of available weapons, armor sets and monsters respectively.
The following n lines describe available weapons. The i-th of these lines contains two integers ai and cai (1≤ai≤106, 1≤cai≤109) — the attack modifier and the cost of the weapon i.
The following m lines describe available armor sets. The j-th of these lines contains two integers bj and cbj (1≤bj≤106, 1≤cbj≤109) — the defense modifier and the cost of the armor set j.
The following p lines describe monsters. The k-th of these lines contains three integers xk,yk,zk (1≤xk,yk≤106, 1≤zk≤103) — defense, attack and the number of coins of the monster k.
Output
Print a single integer — the maximum profit of the grind.
Example
inputCopy
2 3 3
2 3
4 7
2 4
3 2
5 11
1 2 4
2 1 6
3 4 6
outputCopy
1
题目意思有多个武器和多个防护的(英语差, ) 物品, 只能各自挑选一个,每个有两种属性,然后去打怪, 如果满足题目中给的条件ai>xk and bj>yk , 就能打倒这个怪物, 然后获得金币(有多少要满足此条件怪物 , 便可以打多少)
求最大收获为多少

首先对于物品, 怪物没有特殊要求, 我们先排序, 这样方便解题
思路:枚举每一个盾牌 , 这个盾牌可以打倒比他低的怪兽 ,同时考虑它打倒的怪物, 看看武器打倒他的最小值, 然后武器值只要大于等于它的都满足条件, 这个时候我们找到了三个条件:枚举的此盾牌, 可以被盾牌打倒的怪物, 还有符合条件的武器范围(大于最小值) , 然后就在这三个条件中求最值
对于盾牌可以打倒的怪物们来说, 可以获得的金币为C[k].c , 然后花费为盾牌和武器, 因为盾牌时枚举的, 最后剪掉就行, 假设此怪物被打倒获得金币a , 则将a加到武器范围大于最小值的, 因为大于最小值的武器皆可以被使用, 然后求最值 , 将此盾牌能打到的怪物全部这样处理 ,
用到的数据结构:范围加一个值, 全局最大值、


```cpp
#include <bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 10 ;
typedef long long ll ;
ll a[N * 4] , lazy[N * 4] ;
void down(int x)
{
  if(lazy[x])
   {
     a[x << 1] += lazy[x] ;
     a[x << 1 | 1] += lazy[x] ;
     lazy[x << 1] += lazy[x] ;
     lazy[x << 1 | 1] += lazy[x] ;
     lazy[x] = 0 ;
   }
}
ll ha[N] ;
void update(int rt , int l , int r , int L , int R , int v)
{
  if(l == L && r == R)
   {
     lazy[rt] += v ;
     a[rt] += v ;
     return ;
   }
   down(rt) ;
   int mid = (l + r) >> 1 ;
   if(R <= mid) update(rt << 1 , l , mid , L , R , v) ;
   else if(L > mid)update(rt << 1 | 1 , mid + 1 , r , L , R , v) ;
   else
    {
      update(rt << 1 , l , mid , L , mid , v) ;
      update(rt << 1 | 1 , mid + 1 , r , mid + 1 , R , v) ;
    }
    a[rt] = max(a[rt << 1] , a[rt << 1 | 1]) ;
}
struct node
{
  int a , b , c ;
}A[N] , B[N] , C[N] ;
bool cmp1(node a , node b)
{
  return a.a < b.a ;
}
bool cmp2(node a , node b)
{
  return a.b < b.b ;
}
int main()
{
  int n , m , p ;
  scanf("%d%d%d" , &n , &m , &p) ;
  for(int i = 1; i <= n ;i ++) scanf("%d%d" , &A[i].a , &A[i].b ) ;
  for(int i = 1; i <= m ;i ++) scanf("%d%d" , &B[i].a , &B[i].b ) ;
  for(int i = 1; i <= p ;i ++) scanf("%d%d%d" , &C[i].a , &C[i].b , &C[i].c) ;
  sort(A + 1 , A + n + 1 , cmp1) , sort(B + 1 , B + m + 1 , cmp1) ;
  sort(C + 1 , C + p + 1 , cmp2) ;
  for(int i = 1; i <= n ;i ++)
   ha[i] = A[i].a , update(1 , 1 , n , i , i , -A[i].b) ;
  ll k = 1 , ans = -1e18 ;
  for(int i = 1; i <= m ;i ++)
   {
     while(k <= p && C[k].b < B[i].a)
      {
        int a = upper_bound(ha + 1 ,ha + n + 1 , C[k].a) - ha  ;
        if(a <= n) update(1 , 1 , n , a , n , C[k].c) ;
        k ++ ;
      }
      ans = max(ans , 1ll * a[1] - B[i].b) ;
   }
  cout << ans << endl ;
  return 0 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值