題意
有一個,下面行,每行有一個和一個,如果爲0,則表示來了個人,如果爲1,則表示第批人走了。(注意一下,每一批人除了還有一個導遊)
樣例
輸入
6
0 5
0 6
1 1
0 7
0 8
1 3
輸出
16
思路
用一個數組去裝來的每一批人,然後統計就OK了
代碼
#include<cstdio>
#include<iostream>
using namespace std;
int n,x,y,t,a[1000001];
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==0) a[++t]=y+1;
else a[y]=0;
}
long long ans=0;
for (int i=1; i<=t; ++i) ans+=a[i];
printf("%lld",ans);
fclose(stdin);
fclose(stdout);
}