【JZOJ】【模拟】博物馆

博物馆

n n 个数,然后有 n n 行,每行两个数, x x y y ,如果 x x 1 1 ,那么代表来了 y y 个人,如果 x x 0 0 ,则代表来的第 y y 批人走了,求最后还有多少人

输入

样例输入
6
0 5
0 6
1 1
0 7
0 8
1 3

输出

样例输出
16

思路

世纪大模拟题

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,x,y,t,a[1000025];
int main()
{
	freopen("museum.in","r",stdin);
	freopen("museum.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&x,&y);
		if(!x)m+=y+1,a[++t]=y+1;
		else m-=a[y];
	}
	printf("%d",m);
	fclose(stdin);
	fclose(stdout);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/SSL_wujiajie/article/details/86712231