10分求调!!
查看原帖
10分求调!!
1394325
Stalin_QwQ楼主2025/1/17 08:50

#include<bits/stdc++.h>
using namespace std;
struct build {
	long long fix;
	long long wait;
	long long cha;
};
bool cmp1(build a, build b) {
	return a.cha < b.cha;
}
int main() {
	long long n;
	cin >> n;
	vector<build> a(n);
	priority_queue<long long, vector<long long>, greater<long long>> q;
	long long sum = 0;
	long long cnt = 0;
	for (long long i = 0; i < n; i++) {
		scanf("%lld %lld", &a[i].fix, &a[i].wait);
		sum += (a[i].wait - a[i].fix);
		a[i].cha = a[i].wait - a[i].fix;
		q.push(a[i].cha);
	}
	stable_sort(a.begin(), a.end(), cmp1);
	long long z = 1; 
	long long dp = 0; 
	while (!q.empty()) {
		sum -= q.top();
		dp+=q.top();
		if(a[z].cha-dp==0) cnt++;
		q.pop();
		z++;
	}
	printf("%lld", cnt);
	return 0;
}

10分求调

2025/1/17 08:50
加载中...