#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int q,l,k;
int t[500005],x[500005],a[500005];
ll b[1500005][2],sum;
vector<int> xs;
ll solve(){
ll mx=0,mx0=-1e18,mx1=0;
for(int i=0;i<k;i++){
ll pmx0=mx0,pmx1=mx1;
mx0=max(pmx0,pmx1-b[i][0]);
mx1=max(pmx1,pmx0+b[i][1]);
mx=max(mx,mx1);
}
return sum-mx;
}
int main(){
q=readint(); l=readint();
for(int i=1;i<=q;i++){
t[i]=readint(); x[i]=readint(); a[i]=readint();
}
for(int i=1;i<=q;i++){
xs.pb(x[i]);
xs.pb(x[i]-l);
xs.pb(x[i]+l);
}
xs.pb((int)-1.00001e9);
sort(xs.begin(),xs.end());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
k=(int)xs.size();
for(int i=1;i<=q;i++){
if(t[i]==1){
int idx=(int)(lower_bound(xs.begin(),xs.end(),x[i])-xs.begin());
for(int j=idx;j<k;j++) b[j][0]+=a[i];
for(int j=idx;j<k;j++) b[j][1]+=a[i];
sum+=a[i];
}else{
int idx=(int)(lower_bound(xs.begin(),xs.end(),x[i]+l)-xs.begin());
for(int j=idx;j<k;j++) b[j][0]-=a[i];
idx=(int)(lower_bound(xs.begin(),xs.end(),x[i]-l)-xs.begin());
for(int j=idx;j<k;j++) b[j][1]-=a[i];
}
printf("%lld\n",solve());
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6588 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
13 ms |
6748 KB |
Output is correct |
7 |
Correct |
11 ms |
6628 KB |
Output is correct |
8 |
Correct |
5 ms |
6492 KB |
Output is correct |
9 |
Correct |
5 ms |
6492 KB |
Output is correct |
10 |
Correct |
58 ms |
6748 KB |
Output is correct |
11 |
Correct |
63 ms |
6744 KB |
Output is correct |
12 |
Correct |
58 ms |
6744 KB |
Output is correct |
13 |
Correct |
60 ms |
6896 KB |
Output is correct |
14 |
Correct |
60 ms |
7004 KB |
Output is correct |
15 |
Correct |
62 ms |
6888 KB |
Output is correct |
16 |
Correct |
57 ms |
6744 KB |
Output is correct |
17 |
Correct |
57 ms |
6748 KB |
Output is correct |
18 |
Correct |
57 ms |
6748 KB |
Output is correct |
19 |
Correct |
58 ms |
6904 KB |
Output is correct |
20 |
Correct |
57 ms |
6744 KB |
Output is correct |
21 |
Correct |
58 ms |
6916 KB |
Output is correct |
22 |
Correct |
57 ms |
6748 KB |
Output is correct |
23 |
Correct |
60 ms |
6896 KB |
Output is correct |
24 |
Correct |
57 ms |
6996 KB |
Output is correct |
25 |
Correct |
59 ms |
6900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Execution timed out |
4033 ms |
24948 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Execution timed out |
4075 ms |
18636 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6588 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
13 ms |
6748 KB |
Output is correct |
7 |
Correct |
11 ms |
6628 KB |
Output is correct |
8 |
Correct |
5 ms |
6492 KB |
Output is correct |
9 |
Correct |
5 ms |
6492 KB |
Output is correct |
10 |
Correct |
58 ms |
6748 KB |
Output is correct |
11 |
Correct |
63 ms |
6744 KB |
Output is correct |
12 |
Correct |
58 ms |
6744 KB |
Output is correct |
13 |
Correct |
60 ms |
6896 KB |
Output is correct |
14 |
Correct |
60 ms |
7004 KB |
Output is correct |
15 |
Correct |
62 ms |
6888 KB |
Output is correct |
16 |
Correct |
57 ms |
6744 KB |
Output is correct |
17 |
Correct |
57 ms |
6748 KB |
Output is correct |
18 |
Correct |
57 ms |
6748 KB |
Output is correct |
19 |
Correct |
58 ms |
6904 KB |
Output is correct |
20 |
Correct |
57 ms |
6744 KB |
Output is correct |
21 |
Correct |
58 ms |
6916 KB |
Output is correct |
22 |
Correct |
57 ms |
6748 KB |
Output is correct |
23 |
Correct |
60 ms |
6896 KB |
Output is correct |
24 |
Correct |
57 ms |
6996 KB |
Output is correct |
25 |
Correct |
59 ms |
6900 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Execution timed out |
4033 ms |
24948 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |