比赛 Segment Tree Competition 评测结果 AAAAAAAAAAAA
题目名称 售票系统 最终得分 100
用户昵称 洛克索耶夫 运行时间 0.525 s
代码语言 C++ 内存使用 1.18 MiB
提交时间 2016-08-28 19:08:53
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

int c,s,r;
int o[60010],d[60010],n[60010];
int a[60010];
bool f[60010];

int Read()
{
	int a = 0, minus = 1;
	char ch = getchar();
	if(ch == '-')       minus = -1;
	while(ch < '0' || ch > '9'){
		ch = getchar();
		if(ch == '-')	minus = -1;
	}
	while(ch >= '0' && ch <= '9'){
		a = a * 10 + ch - '0';
		ch = getchar();
	}
	return a * minus;
}
int main()
{
	freopen("railway.in","r",stdin);
	freopen("railway.out","w",stdout);
	c = Read(), s = Read(), r = Read();
	for(int i = 1; i <= r;i++)
	{
		o[i] = Read();
		d[i] = Read();
		n[i] = Read();
		if(d[i] > c){
			f[i] = true;
			continue;
		}
		for(int j = o[i]; j < d[i]; j++){
			if(a[j] + n[i] <= s)
				a[j] += n[i];
			else{
				f[i] = true;
				for(int k = j-1; k >= o[i]; k--)
					a[k] -= n[i];
				break;
			}
		}
	}
	for(int i = 1; i <= r; i++){
		if(!f[i])	puts("YES");
		else 	puts("NO");
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}