this is AC code:
#include<nuts/stdc++.h>
using namespace std;
int tb=0,te=0,T[100005],c[100005];
bool b[100005];
int main()
{
//freopen("transfer.in","r",stdin);
//freopen("transfer.out","w",stdout);
int n;
cin>>n;
int ans=0;
for(int j=0;j<n;j++)
{
int p,t,type;
cin>>type>>p>>t;
if(type==0)
{
T[te]=t;
c[te]=p;
te++;
ans+=p;
}
else
{
bool flag=true;
while (tb<te&&t-T[tb]>45) {
tb++;
}
for(int i=tb;i<=te;i++)
{
//if(t-T[i]>45)tb++;
if(p<=c[i]&&b[i]==false)
{
b[i]=true;
flag=false;
break;
}
}
if(flag)ans+=p;
}
}
cout<<ans;
return 0;
}
/*
6
0 10 3
1 5 46
0 12 50
1 3 96
0 5 110
1 6 135
*/
/*
6
0 5 1
0 20 16
0 7 23
1 18 31
1 4 38
1 7 68
*/
this is wa code:
#include<bits/stdc++.h>
using namespace std;
int tb=1,te=1,T[100005],c[100005];
bool b[100005];
int main()
{
//freopen("transfer.in","r",stdin);
//freopen("transfer.out","w",stdout);
int n;
cin>>n;
int ans=0;
while(n--)
{
int p,t,type;
cin>>type>>p>>t;
if(type==0)
{
T[te]=t;
c[te]=p;
te++;
ans+=p;
}
else
{
bool flag=true;
for(int i=tb;i<=te;i++)
{
if(t-T[i]>45)tb++;
else if(t-T[i]<=45&&p<=c[i]&&b[i]==false)
{
b[i]=true;
flag=false;
break;
}
}
if(flag)ans+=p;
}
}
cout<<ans;
return 0;
}
/*
6
0 10 3
1 5 46
0 12 50
1 3 96
0 5 110
1 6 135
*/
/*
6
0 5 1
0 20 16
0 7 23
1 18 31
1 4 38
1 7 68
*/
唯一的差别就是wa的在选票的时候淘汰过气的票,为何wa了呢?