题解分享
题解分享简介
最少刷题数(编程题) - 题解
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
int n;
cin >> n;
int a[N]={0};
int sum[N] = {0};
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[a[i]]++;
}
for (int i = 1; i < N; i++) {
sum[i] += sum[i - 1];
}
for (int i = 1; i <= n; i++) {
int b = sum[N - 1] - sum[a[i]];
int c= sum[a[i]-1];
int ans = 0;
while (b > c) {
ans++;
b=sum[N-1]-sum[a[i]+ans];
c=sum[a[i] + ans-1]-1;
}
cout << ans;
if (i < n) {
cout << " ";
}
}
return 0;
}
```
```
```
查看全文
0
0
0
2



