洛谷 P4857 求条

题目

94 分代码:

#include<bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
int n, i, a[N];
ll m, L, R, mid, fin, now, ans[N];
priority_queue<P, vector<P>, greater<P> >Q;
inline void read(int&a) {
	char c;
	while (!(((c = getchar()) >= '0') && (c <= '9')));
	a = c - '0';
	while (((c = getchar()) >= '0') && (c <= '9'))(a *= 10) += c - '0';
}
bool check(ll x) {
	ll t = m;
	for (int i = 1; i <= n; i++) {
		t -= x / a[i];
		if (t < 0)return 0;
	}
	return 1;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	scanf("%lld", &m);
	read(n);
	for (i = 1; i <= n; i++) {
		read(a[i]);
		if (a[i] > R)R = a[i];
	}
	L = R + 1, R *= m;
	while (L <= R)if (check(mid = (L + R) >> 1))L = (fin = mid) + 1;
		else R = mid - 1;
	for (R = fin, i = 1; i <= n; i++)R = min(R, max((fin / a[i] - 1) * a[i], 0LL));
	for (i = 1; i <= n; i++)now += R / a[i], Q.push(P(R / a[i] * a[i], i));
	while (now < m) {
		P t = Q.top();
		Q.pop();
		ans[t.second] = ++now;
		t.first += a[t.second];
		Q.push(t);
	}
	for (i = 1; i < n; i++)printf("%lld ", ans[i]);
	printf("%lld", ans[n]);
	return 0;
}

用你的代码我A了?一点都没改诶。。。我运气太好了

A 了???

A了

开O2优化了吗?我用的c++20

OKOK,AC了