蒟蒻快疯了!!!!求助
查看原帖
蒟蒻快疯了!!!!求助
703319
Sylvia_starx楼主2022/8/22 09:27
#include<bits/stdc++.h>
using namespace std;
struct node{
	int start,end;
}a[5100];
int n;
long long you,wu;
bool cmp(node x,node y)
{
	return x.end<y.end;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].start>>a[i].end;
	}
	int last = a[1].end;
	you += a[1].end - a[1].start;
	for(int i=2;i<=n;i++)
	{
		if(a[i].start == last)
		{
			you += a[i].end - a[i].start;
		}
		else if(a[i].start < last)
		{
			a[i].start = last;
			you += a[i].end - a[i].start;
		}else
		{
			wu += a[i].start - last;
		}
		last = a[i].end;
	}
	cout<<you<<" "<<wu;
	return 0;
}

55555…………

帮帮我吧!!

2022/8/22 09:27
加载中...