Train Seats Reservation

You are given a list of train stations, say from the station 111 to the station 100100100.

The passengers can order several tickets from one station to another before the train leaves the station one. We will issue one train from the station111 to the station 100100100 after all reservations have been made. Write a program to determine the minimum number of seats required for all passengers so that all reservations are satisfied without any conflict.

Note that one single seat can be used by several passengers as long as there are no conflicts between them. For example, a passenger from station111 to station 101010 can share a seat with another passenger from station 303030 to 606060.

Input Format

Several sets of ticket reservations. The inputs are a list of integers. Within each set, the first integer (in a single line) represents the number of orders,nnn, which can be as large as 100010001000. After nnn, there will be nnn lines representing the nnn reservations; each line contains three integers s,t,ks, t, ks,t,k, which means that the reservation needs kkk seats from the station sss to the station ttt .These ticket reservations occur repetitively in the input as the pattern described above. An integern=0n = 0n=0 (zero) signifies the end of input.

Output Format

For each set of ticket reservations appeared in the input, calculate the minimum number of seats required so that all reservations are satisfied without conflicts. Output a single star '*' to signify the end of outputs.

样例输入
2
1 10 8
20 50 20
3
2 30 5
20 80 20
40 90 40
0
样例输出
20
60
*
#include <stdio.h>
#include <string.h>
int a[1000];
int main(int argc, char *argv[])
{
	int t;
	while(scanf("%d",&t)!=EOF)
	{
		int i,j;
		if(t==0)
		{
			printf("*\n");
			break;
		}
		memset(a,0,sizeof(a));
		for(i=0;i<t;i++)
		{
			int c,d,e;
			scanf("%d %d %d",&c,&d,&e);
			for(j=c;j<d;j++)
			{
				a[j]+=e;		
			}
		}
		int max=-1;
		for(i=0;i<=100;i++)
		{
			if(max<a[i])
			{
				max=a[i];
			}
		}
		printf("%d\n",max);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值