B-Gaming
题意:
思路:枚举不带上每一个debuff的情况,当枚举到第i个debuff时,用pre[x]记录x<l[i]的前缀和,用suf[x]记录x>r[i]的后缀和,答案就ans=max(ans,pre[i-1]+suf[i+1])。这样子一定可以保证关于第i个debuff的这一段区间的积分没有被算进去。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int l[N],r[N],s[N];
ll pre[N],suf[N];
int n,m;
int main(){
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++){
scanf("%d%d%d",&l[i],&r[i],&s[i]);
pre[r[i]]+=s[i];
suf[l[i]]+=s[i];
}
for(int i = 1; i <= m; i++)
pre[i]+=pre[i-1];
for(int i = m; i >= 0; i--)
suf[i]+=suf[i+1];
ll ans=0;
for(int i = 1; i <= m; i++){
ans=max(ans,pre[i-1]+suf[i+1]);
}
printf("%lld\n",ans);
return 0;
}