F. Cutlet
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried for n seconds on one side and n seconds on the other side. Arkady has already got a frying pan and turn on fire, but understood that maybe he won't be able to flip the cutlet exactly after n seconds after the beginning of cooking.

Arkady is too busy with sorting sticker packs in his favorite messenger and can flip the cutlet only in some periods of time. Namely, there are k periods of time in which he can do it, the i-th of them is an interval of time from li seconds after he starts cooking till ri seconds, inclusive. Arkady decided that it's not required to flip the cutlet exactly in the middle of cooking, instead, he will flip it several times in such a way that the cutlet will be fried exactly n seconds on one side and n seconds on the other side in total.

Help Arkady and find out if it's possible for him to cook the cutlet, if he is able to flip the cutlet only in given periods of time; and if yes, find the minimum number of flips he needs to cook the cutlet.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 100) — the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it.

The next k lines contain descriptions of these intervals. Each line contains two integers li and ri(0 ≤ li ≤ ri ≤ 2·n), meaning that Arkady can flip the cutlet in any moment starting from li seconds after the beginning of cooking and finishing at ri seconds after beginning of cooking. In particular, if li = ri then Arkady can flip the cutlet only in the moment li = ri. It's guaranteed that li > ri - 1 for all 2 ≤ i ≤ k.

Output

Output "Hungry" if Arkady won't be able to fry the cutlet for exactly n seconds on one side and exactly nseconds on the other side.

Otherwise, output "Full" in the first line, and the minimum number of times he should flip the cutlet in the second line.

Examples
input

Copy
10 2
3 5
11 13
output
Full
2
input

Copy
10 3
3 5
9 10
11 13
output
Full
1
input

Copy
20 1
3 19
output
Hungry
Note

In the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.

In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking.

题意:

有一个烤肉,需要正面烤N秒,反面烤N秒。

给出K个时间区间,在这些区间内可以翻转烤肉

N<=100000                 K<=100

http://blog.csdn.net/Charlie_jilei/article/details/79342492

直接推荐一篇题解(我不会,抄他的,逃)

 /*
Welcome Hacking
Wish You High Rating
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int read(){
int xx=,ff=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')ff=-;ch=getchar();}
while(ch>=''&&ch<=''){xx=xx*+ch-'';ch=getchar();}
return xx*ff;
}
int N,K,f[][];
struct Segment{
int L,R;
}S[];
int q[],head,tail;
int main(){
//freopen("in","r",stdin);
N=read(),K=read();
for(int i=;i<=K;i++)
S[i].L=read(),S[i].R=read();
for(int j=;j<=N;j++)
f[][j]=(<<);
f[][]=;
for(int i=;i<=K;i++){
for(int j=;j<=N;j++)
f[i][j]=f[i-][j];
head=,tail=;
for(int j=;j<=S[i].R;j++){
if(j<=N){
while(head<=tail&&f[i-][j]<=f[i-][q[tail]])
tail--;
q[++tail]=j;
}
while(head<=tail&&q[head]<=j-(S[i].R-S[i].L+))
head++;
if(head<=tail)
f[i][j]=min(f[i][j],f[i-][q[head]]+);
}
head=,tail=;
for(int j=S[i].R;j>=;j--){
if(S[i].R-j<=N){
while(head<=tail&&f[i-][S[i].R-j]<=f[i-][q[tail]])
tail--;
q[++tail]=S[i].R-j;
}
while(head<=tail&&q[head]<=S[i].L-(j+))
head++;
if(head<=tail)
f[i][j]=min(f[i][j],f[i][q[head]]+);
}
}
if(f[K][N]>=(<<))
puts("Hungry");
else{
puts("Full");
printf("%d\n",f[K][N]);
}
return ;
}

最新文章

  1. java用selenium库控制chrome
  2. 如何使用JDBC实现数据访问对象层(DAO)
  3. sqlserver -- 学习笔记(八)体验charindex、stuff 和 for xml path在实际问题中的应用及几个问题的探讨
  4. css3 -- 多列
  5. MyEclipse中拷贝J2EE项目,发布到tomcat中名字一样的解决办法
  6. cereal:C++实现的开源序列化库
  7. 【kAri OJ620】winoros的树
  8. 64 位win 7或windows 8下的visual studio不能连接Oracle数据库调试网站的问题
  9. 浏览器 CSS 兼容写法的测试总结
  10. PC-lint集成于SourceInsight 范例以及简单分析;提高代码的健壮性;
  11. ArrayList在foreach正常迭代删除不报错的原因
  12. 如果没有Build path怎么办 .project文件的修改
  13. Magicodes.WeiChat——使用OAuth 2.0获取微信用户信息
  14. Kettle解决方案: 第一章ETL入门
  15. Oracle 外键级联更新
  16. zabbix python 微信告警脚本
  17. Ubuntu 18.04 上设置桌面程序开机自启动
  18. CH0103 最短Hamilton路径 dp
  19. Python os.chmod
  20. AngularJs 第一个自定义指令编写

热门文章

  1. CAD设置水印
  2. Redis系列(十)--集群cluster
  3. webpack之webpack-dev-server 与 webpack-hot-server
  4. C++/C union使用记一下锅
  5. asp.net mvc,基于aop实现的接口访问统计、接口缓存等
  6. SQLAlchemy-Utils
  7. Error:Cannot find bean: &quot;org.apache.struts.taglib.html.BEAN&quot; in any scope
  8. LINUX-JPS工具
  9. Java核心技术 卷一 复习笔记(乙
  10. naca0012