CodeForces - 44C Holidays

Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

 Status

Description

School holidays come in Berland. The holidays are going to continue for n days. The students of school №N are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people are in charge of the daily watering of flowers in shifts according to the schedule. However when Marina Sergeyevna was making the schedule, she was so tired from work and so lost in dreams of the oncoming vacation that she perhaps made several mistakes. In fact, it is possible that according to the schedule, on some days during the holidays the flowers will not be watered or will be watered multiple times. Help Marina Sergeyevna to find a mistake.

Input

The first input line contains two numbers n and m (1 ≤ n, m ≤ 100) — the number of days in Berland holidays and the number of people in charge of the watering respectively. The next m lines contain the description of the duty schedule. Each line contains two integers ai and bi(1 ≤ ai ≤ bi ≤ n), meaning that the i-th person in charge should water the flowers from the ai-th to the bi-th day inclusively, once a day. The duty shifts are described sequentially, i.e. bi ≤ ai + 1 for all i from 1 to n - 1 inclusively.

Output

Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers — the day number and the number of times the flowers will be watered that day.

Sample Input

Input
10 5
1 2
3 3
4 6
7 7
8 10
Output
OK
Input
10 5
1 2
2 3
4 5
7 8
9 10
Output
2 2
Input
10 5
1 2
3 3
5 7
7 7
7 10
Output
4 0

Hint

Keep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number.

前缀和水题

#include<iostream>
using namespace std;
int main()
{
	int n, m;
	while (cin >> m >> n)
	{
		int aa, bb;
		int a[101] = { 0 };
		for (int i = 0; i < n; i++)
		{
			cin >> aa >> bb;
			a[aa]++;
			a[bb+1]--;			
		}
		int sum[102];
		sum[0] = a[0];
		for (int i = 1; i <= m; i++)
		{
			sum[i] = sum[i-1] + a[i];
		}
		int ok = 1;
		for (int i = 1; i <= m; i++)
		if (sum[i]!=1)
		{
			ok = 0;
			cout << i << " " << sum[i] << endl;
			break;
		}
		if (ok) cout << "OK" << endl;
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

这波lucio来全学了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值