感觉思路没什么问题,是题目理解错了?( Hack 数据过了)
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int n,m,k,f[N],d[N],dp[N];
struct Edge{
int x,key;
};
struct Per{
int t,l,r,x;
}p[N],p2[N],p3[N];
Edge e[N];
int chaf[N],Wait[N],wt[N];
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<n;i++){
cin>>d[i];
e[i].x=i;
}
for(int i=1;i<=m;i++){
scanf("%d%d%d",&p[i].t,&p[i].l,&p[i].r);
for(int j=p[i].l;j<=p[i].r;j++)e[i].key++;
p[i].x=i;
chaf[p[i].r+1]--;
chaf[p[i].l]++;
wt[p[i].l]=max(wt[p[i].l],p[i].t);
}
memcpy(p2,p,sizeof p);
memcpy(p3,p,sizeof p);
for(int i=1;i<n;i++){
e[i].key=e[i-1].key+chaf[i];
}
sort(e+1,e+n,[](const Edge& a,const Edge& b){return a.key>b.key;});
for(int i=1;i<n;i++){
if(k==0)break;
if(d[e[i].x]>k)d[e[i].x]-=k,k=0;
else k-=d[e[i].x],d[e[i].x]=0;
}
int ans=0;
//理一下:
//d[i]:第i条边现在的长度
//e[i].key:第i条边的人数
//wt[i]:第i个点要等到wt[i]分
//思路:每次时间+1,直到最后一个人离开
sort(p+1,p+m+1,[](const Per& a,const Per& b){return a.t<b.t;});
sort(p2+1,p2+m+1,[](const Per& a,const Per& b){return a.l<b.l;});
sort(p3+1,p3+m+1,[](const Per& a,const Per& b){return a.r<b.r;});
int ponc=0,pwt=m,pdone=0,pp=1;//ponc:车上的人数 pwt:没上车的人数 pdone:下车的人数 pp:第pp个人还没上车
int curd=0,curg=0;//curd:出站的最后一个人 curg:类似
int curt=0,cp=1;//curt:当前时间 cp:车的位置(路上不考虑)
while(pdone<m){//p:按到站时间排序 p2:按进站位置排序 p3:按出站位置排序
//任务:推算出每个乘客i到达终点的时间dp[i]
//流程:上车——开一站——下车
if(curt<wt[cp]){
curt=wt[cp];
}
while(p2[curg+1].l==cp){
++ponc;
--pwt;
++curg;
}
curt+=d[cp];
++cp;
while(p3[curd+1].r==cp){
--ponc;
++pdone;
++curd;
dp[p3[curd].x]=curt;
}
}
for(int i=1;i<=m;i++){
// cout<<dp[i]<<endl;
ans+=dp[i]-p[i].t;
}
cout<<ans<<endl;
}
没过的数据点:
16 100 1
5 6 5 8 9 6 2 6 9 1 1 9 7 2 4
16 8 14
23 4 14
1 1 13
1 1 8
25 9 16
3 5 12
11 2 4
64 12 14
4 2 15
24 4 12
14 3 13
5 7 10
1 1 2
1 1 2
8 2 3
8 2 13
6 3 4
29 6 7
9 2 12
78 13 16
11 3 5
1 1 2
1 1 2
3 4 5
1 2 5
8 3 11
1 1 2
58 7 13
48 12 13
19 10 14
1 1 2
25 4 6
37 6 9
7 2 10
10 5 6
1 1 7
36 7 8
2 3 6
5 4 12
5 3 9
26 4 5
6 4 14
1 2 10
1 1 7
50 6 9
6 3 4
1 1 3
5 2 12
17 6 8
11 2 14
7 2 7
25 8 10
1 1 2
7 6 10
2 3 4
4 2 15
28 5 9
8 2 10
7 8 16
7 3 5
3 3 14
55 8 16
6 3 12
17 8 9
6 2 4
1 2 3
7 5 6
5 3 11
55 14 15
59 7 8
30 5 9
1 1 10
34 5 7
51 6 12
29 9 10
130 14 15
6 2 3
9 2 7
13 4 6
4 3 12
14 4 12
51 7 8
6 9 15
3 2 14
19 8 13
5 6 12
24 4 6
8 2 9
10 3 4
1 2 7
23 5 8
38 7 16
9 6 13
1 2 3
97 14 15
30 10 14
47 10 12
1 1 9
3 5 10
1 1 14
输出:
4909