标签:efi head algorithm can scan stack csharp str name
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> const int MAXN=1e4+15; #define ll long long using namespace std; ll f[MAXN]; int sum[MAXN],sumtimee[MAXN]; int num[MAXN]; int n,m; int s; int tail,head,que[MAXN]; int i; int main(){ scanf("%d%d",&n,&s); for(i=1;i<=n;i++) { scanf("%d%d",&sumtimee[i],&num[i]); sum[i]=sum[i-1]+num[i];sumtimee[i]=sumtimee[i-1]+sumtimee[i]; } head=tail=1; que[tail++]=0; for(i=1;i<=n;i++) { while(head+1<tail&&(f[que[head+1]]-f[que[head]])<=(s+sumtimee[i])*(sum[que[head+1]]-sum[que[head]])) head++; int k=que[head]; f[i]=f[k]-(s+sumtimee[i])*sum[k]+sumtimee[i]*sum[i]+s*sum[n]; while(head+1<tail&&(f[i]-f[que[tail-1]])*(num[que[tail-1]]-num[que[tail-2]])<=(num[i]-num[que[tail-1]])*(f[que[tail-1]]-f[que[tail-2]])) tail--; que[tail++]=i; } printf("%lld",f[n]); return 0; }
标签:efi head algorithm can scan stack csharp str name
原文地址:https://www.cnblogs.com/Lamboofhome/p/11605196.html