题解 | #神秘金币#
手术
https://ac.nowcoder.com/acm/contest/65187/D
D 手术 不知道正确解法,直接set暴力水过了捏
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define x first
#define y second
#define pd push_back
#define pii pair<double,double>
#define It set<ran>::iterator
typedef long long ll;
const int maxn=1e5+5;
struct ren
{
int p;
ll t,a,b;
ll ***重度, 到达时间,a元,b时长
} A[maxn];
bool cmp(ren &a,ren &b)
{
return a.p<b.p;//先按照病情从小到大
}
vector<int>v[maxn];
int n,k;
struct ran
{
ll l, r;
mutable int v;
bool operator <(const ran &x)const
{
return l < x.l;
}
};
struct LuanXie
{
set<ran>tr;
ll ans=0;
void emerge(ll l, ll r, ll x,ll a)
{
if(tr.empty())
{
cout<<ans;
exit(0);
}
It it = tr.lower_bound({l, -1, 0});
--it;
--it;
for(; it!=tr.end(); it++) //
{
if(it->l <= l && r <= it->r)//(l,r)
{
int L = it->l;
int R = it->r;
ans+=a;
tr.erase(it);
if(L<l)tr.insert({L, l - 1, 0});
if(r<R)tr.insert({r+1, R, 0});
return;
}
else if((it->l >=l) &&(((it->r)-(it->l)+1)>=x))
{
ans+=a;
int L = it->l;
int R = it->r;
tr.erase(it);
if(L+x<=R)tr.insert({L+x, R, 0});
return;
}
}
cout<<ans;
exit(0);
}
} luanxie;
int main()
{
IO;
cin>>n>>k;
for(int i=1; i<=n; i++)cin>>A[i].p;
for(int i=1; i<=n; i++)cin>>A[i].t;
for(int i=1; i<=n; i++)cin>>A[i].a;
for(int i=1; i<=n; i++)cin>>A[i].b;
sort(A+1,A+n+1,cmp);
luanxie.tr.insert({1,k,0});
for(int i=1; i<=n; i++)
{
if(A[i].t+A[i].b>k)continue;
luanxie.emerge(A[i].t,A[i].t+A[i].b-1,A[i].b,A[i].a);
}
cout<<luanxie.ans;
return 0;
}