6个RE
查看原帖
6个RE
326254
LonginusMonkey楼主2023/10/24 21:53

数组开大也没什么用

#include<bits/stdc++.h>
#define int long long
using namespace std;
bool is[2500010];
int a[2500010];
int b[2500010];
priority_queue<pair<int,int> > que;
signed main() {
	int n; cin >> n;
	for(int i=1; i<=n; ++i) {
		cin >> a[i];
	}
	for(int i=1; i<=n; ++i) {
		cin >> b[i];
	}
	int chun = 0; int ans = 0;
	for(int i=1; i<=n; ++i) {
		if(a[i]+chun>=b[i]) {
			chun = chun + a[i] - b[i];
			que.push({b[i], i});
			is[i] = 1;
			ans++;
		} else {
			int fir = que.top().first;
			int sec = que.top().second;
			if(chun + fir +a[i] >= b[i]) {
				chun = chun + fir + a[i] - b[i];
				que.pop();
				que.push({b[i], i});
				is[i] = 1;
				is[sec] = 0;
			} else {
				chun += a[i];
			}
		}
	}
	cout << ans << endl;
	for(int i=1; i<=n; ++i) {
		if(is[i]) {
			cout << i << " ";
		}
	}
	return 0;
}
2023/10/24 21:53
加载中...