观光公交 贪心 思维
Code:
#include<cstdio> #include<algorithm> #include<string> using namespace std; void setIO(string a){ freopen((a+".in").c_str(),"r",stdin);} void shutIO(){ fclose(stdin);} #define maxn 1006 #define maxm 1000005 struct Node{ int st, ed,t; }e[maxm]; int sum[maxn],last[maxn],d[maxn],out[maxn],tim[maxn],range[maxn]; int main(){ // setIO("input"); int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<n;++i) scanf("%d",&d[i]); for(int i=1;i<=m;++i){ scanf("%d%d%d",&e[i].t,&e[i].st,&e[i].ed); last[e[i].st]=max(last[e[i].st], e[i].t); out[e[i].ed]+=1; } for(int i=1;i<n;++i) tim[i+1]=max(tim[i], last[i])+d[i]; long long ans=0; for(int i=1;i<=n;++i) sum[i]=sum[i-1]+out[i]; for(int i=1;i<=m;++i) ans+=tim[e[i].ed]-e[i].t; while(k--){ int flag=0,cur=0; range[n-1]=n; for(int i=n-2;i>=1;--i){ if(tim[i+1]>last[i+1]) range[i]=range[i+1]; else range[i]=i+1; } for(int i=1;i<=n;++i) if(sum[range[i]]-sum[i]>cur&&d[i]){ cur=sum[range[i]]-sum[i]; flag=i; } if(cur==0) break; ans-=cur; d[flag]-=1; tim[1]=0; for(int i=1;i<n;++i) tim[i+1]=max(tim[i],last[i])+d[i]; } printf("%lld\n",ans); shutIO(); return 0; }