?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
132189881 |
Practice: Untitled37 |
939F - 31 | C++14 (GCC 6-32) | Accepted | 31 ms | 2360 KB | 2021-10-17 09:50:51 | 2021-10-17 09:50:51 |
#include<bits/stdc++.h> using namespace std; #define N 100010 #define INF 0x3f3f3f3f int h,t,q[N<<1]; int n,K,l,r,f[2][N<<1]; int main(){ memset(f[0],0x3f,sizeof(f[0])); f[0][0]=0; scanf("%d%d",&n,&K); for(int i=1;i<=K;++i){ scanf("%d%d",&l,&r); for(int j=0;j<=n;++j) f[i&1][j]=f[!(i&1)][j]; h=1;t=0; for(int j=r;j>=0;--j){ while(h<=t&&q[h]<l-j) ++h; while(h<=t&&f[!(i&1)][q[t]]>f[!(i&1)][r-j]) --t; q[++t]=r-j; f[i&1][j]=min(f[i&1][j],f[!(i&1)][q[h]]+1); } h=1; t=0; for(int j=0,mj=min(n,r);j<=mj;++j){ while(h<=t&&q[h]<j-r+l) ++h; while(h<=t&&f[!(i&1)][q[t]]>f[!(i&1)][j]) --t; q[++t]=j; f[i&1][j]=min(f[i&1][j],f[!(i&1)][q[h]]+2); } } if(f[K&1][n]==INF)printf("Hungry\n"); else printf("Full\n%d\n",f[K&1][n]); }
?
?
?
?