AtCoder Beginner Contest 221 D(思维

D - Online games
题解

code:

#include
#define ll long long
using namespace std;
const int maxn = 2e5 + 9;

int ans[maxn];
void work()
{
     
	int n;cin >> n;
	int a, b;
	vector <pair<int,int> > v;
	int cnt = 0;
	for(int i = 1; i <= n; ++i)
	{
     
		cin >> a >> b;
		v.push_back({
     a, 1});
		v.push_back({
     a + b, -1});
	}
	sort(v.begin(), v.end());
	/*cout << endl;
	for(int i = 0; i < v.size(); ++i)
		cout << v[i].first << " " << v[i].second << endl;*/
	for(int i = 0; i < v.size() - 1; ++i)
	{
     
		cnt += v[i].second;
		ans[cnt] += (v[i + 1].first - v[i].first);
	}
	for(int i = 1; i <= n; ++i)
		cout << ans[i] << " ";
}

int main()
{
     
	ios::sync_with_stdio(0);
	work();
	return 0;
}
/*
1 2
  2 3 4
    3
*/

你可能感兴趣的:(没理解很好的题目,思维题,ios,c++)