First of all, should try to let the food slow row in front, first by this row order
and decide which way everyone is going.
Set F[i][j] is done with the first person, then the 1th window currently has a total queue time of J, the current maximum total time
With this I and J words, and then preprocess the former I personal queue total time sum[i], you can know that the queue time in window 2nd is sum[i]-j
Just take two to update the answer.
1#include <bits/stdc++.h>2 #definePA pair<int,int>3 #defineCLR (a,x) memset (A,x,sizeof (a))4 using namespacestd;5typedefLong Longll;6 Const intmaxn= About;7 8 Inline LL Rd () {9ll x=0;CharC=getchar ();intneg=1;Ten while(c<'0'|| C>'9'){if(c=='-') neg=-1; c=GetChar ();} One while(c>='0'&&c<='9') x=x*Ten+c-'0', c=GetChar (); A returnx*neg; - } - the intf[maxn][maxn*MAXN],ST[MAXN]; - intN; - structnode{ - inte,q; + }P[MAXN]; - +InlineBOOLCMP (Node A,node b) {returnA.e>B.E;} A at intMain () { - //freopen ("", "R", stdin); - inti,j,k; -n=Rd (); - for(i=1; i<=n;i++){ -P[i].q=rd (), p[i].e=Rd (); in}sort (p+1, p+n+1, CMP); - for(i=1; i<=n;i++) tost[i]=st[i-1]+p[i].q; + -CLR (F,127); f[0][0]=0; the for(i=1; i<=n;i++){ * for(j=0; j<=n* $; j + +){ $ if(f[i-1][J]>=1E8)Continue;Panax NotoginsengF[i][j+p[i].q]=min (F[i][j+p[i].q],max (f[i-1][j],j+p[i].q+p[i].e)); -F[i][j]=min (F[i][j],max (f[i-1][j],st[i]-j+p[i].e)); the } + } A intans=1e9; the for(j=0; j<=n* $; j + +) +ans=min (ans,f[n][j]); -printf"%d\n", ans); $ return 0; $}
luogu2577/bzoj1899 Lunch (greedy +dp)