题意:
解法:
只要令a1[i]=a[i]/c, 就可以将
s1[i]+s1[j]>=i*j*c变为s1[i]+s1[j]>=i*j
因此我们在思考时只需要考虑c=1的情况即可.
s[i]+s[j]>=i*j
s[i]+s[j]>=(i-1)*j+j
s[i]+s[j]>=(i-1)*(j-1)+i+j-1>=i+j-1
因此对于可以连边的点i和j, 条件s[i]>=i和s[j]>=j至少满足一个.
如果两者都不满足则s[i]+s[j]<=(i-1)+(j-1),
显然不满足上面s[i]+s[j]>=i+j-1的条件.
同时我们能注意到,当i=1时,式子会变为s[1]+s[j]>=j, 即s[1]>=j-s[j]
假设i和j可以连边,根据上面的推导,一定有s[i]>=i或s[j]>=j.
这里我们不妨假设s[i]>=i.
那么一定有s[1]+s[i]>=i.
因此点i和点j连,可以转化为点i先和点1连,再和点j连。
显然这样更优。
因此我们要做的就是,先将点1和所有满足s[i]>=i的点连接.
连完后, 对于剩余的点j, 优先将点1和j-s[j]最小的点j连接即可.
Code:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int, int>
const int maxm = 2e5 + 5;
int a[maxm];
int n, c;
void solve() {
cin >> n >> c;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
set<PI> s;
for (int j = 2; j <= n; j++) {
s.insert({j * c - a[j], j});
}
int s1 = a[1];
while (s.size()) {
int v = s.begin()->first;
int idx = s.begin()->second;
if (s1 >= v) {
s1 += a[idx];
s.erase(s.begin());
} else {
break;
}
}
if (s.size()) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
signed main() {
#define MULTI_CASE
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("../in.txt", "r", stdin);
freopen("../out.txt", "w", stdout);
#endif
#ifdef MULTI_CASE
int T;
cin >> T;
while (T--)
#endif
solve();
return 0;
}