首页 > 其他分享 >牛客小白月赛54 B.Gaming(差分)

牛客小白月赛54 B.Gaming(差分)

时间:2022-08-13 12:45:35浏览次数:70  
标签:Gaming int 54 LL cin long 牛客 debuff ans

链接:https://ac.nowcoder.com/acm/contest/38457/B

他玩的游戏共有 n 个挑战房间,和 m 个 debuff。他非常强,只要不是带着所有的 debuff,他都能打过 boss 获得胜利。

进入第 i 个房间会使他带上编号在 [li,ri]上的所有 debuff,并获得 si积分。

如果多次获得编号为 x 的 debuff,视为身上带有,但仅带有一个。

他想要知道,在自己能打过 boss(即身上没有集满所有 m 个 debuff)的情况下,他能获得的最大积分是多少?
输入
4 5
1 3 30
2 2 40
2 5 80
2 4 60
输出
180
示例2
输入
1 3
1 3 114514
输出
0
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=2002000;
LL a[N];
int main()
{
    //cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
    LL n,m;
    cin>>n>>m;
    LL ans=0;
    for(LL i=1;i<=n;i++)
    {
        LL l,r,c;
        cin>>l>>r>>c;
        ans+=c;
        a[l]+=c;
        a[r+1]-=c;
    }
    /*for(int i=1;i<=m;i++)
        cout<<a[i]<<" ";
    cout<<endl;*/
    LL minn=1e18,sum=0;
    for(LL i=1;i<=m;i++)
    {
        sum+=a[i];
        //cout<<sum<<" ";
        minn=min(minn,sum);
    }
    cout<<ans-minn<<endl;
    return 0;
}

标签:Gaming,int,54,LL,cin,long,牛客,debuff,ans
From: https://www.cnblogs.com/Vivian-0918/p/16582797.html

相关文章