D. Strong Vertices
条件转移一下即可
由a[u]−a[v]≥b[u]−b[v],可得a[u]-b[u]>=a[v]-b[v]。
设c[i]=a[i]-b[i],由题意得只要c[i]>=cj,点i就有指向j的路。
因此题目就转化成:求c数组中最大元素的个数及其位置。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10;
LL a[N],b[N],q[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
LL mx = -1e11;
for (int i = 1; i <= n; i++) a[i] = a[i] - b[i], mx = max(mx, a[i]);
int ans = 0;
for (int i = 1; i <= n; i++) if (a[i] == mx) q[++ans]=i;
cout << ans<<'\n';
for (int i = 1; i <= ans; i++) cout << q[i] << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}