比赛 平凡的题目 评测结果 WAWWWEEEEW
题目名称 平凡的题面 最终得分 10
用户昵称 VG|Kn. 运行时间 0.338 s
代码语言 C++ 内存使用 1.17 MiB
提交时间 2015-11-03 09:15:03
显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;

const int maxn = 1000 + 10;
int n, m;
int len[maxn];
int f, mc;
int cnt = 0;

struct node
{
	int l;
	int r;
	int c;
	bool b[maxn];
}p[maxn];

int main()
{
	freopen("bg.in","r",stdin);
	freopen("bg.out","w",stdout);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> len[i];
	for (int i = 1; i <= m; i++)
	{
		cin >> p[i].l >> p[i].r;
		p[i].c = p[i].r - p[i].l;
	}
	for (int i = 1; i <= m; i++)
		for (int j = 1; j <= n; j++)
		{
			p[i].b[j] = false;
			if (len[j] >= p[i].l && len[j] <=p[i].r)
				p[i].b[j] = true;
		}
	bool x;
	for (int i = 1; i <= n; i++)
	{
		mc = 200000;
		x = false;
		for (int j = 1; j <= m; j++)
		{
			if (p[j].b[i] == true)
			{
				if (p[j].c < mc)
				{
					mc = p[j].c;
					f = j;
					x = true;
				}
			}
		}
		if (x == true)
		{
			cnt++;
			for (int k = 1; k <= n; k++)
			{
				p[f].b[k] = false;
			}
		}
	}
	cout << cnt;
	return 0;
}