# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1130247 | sohamsen15 | Dancing Elephants (IOI11_elephants) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 999999;
int a[50005];
int n, l;
void init(int N, int L, int X[]) {
n = N; l = L;
for (int i = 0; i < n; i++)
a[i] = X[i];
}
int getMax(int arr[], int n) {
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
void countSort(int arr[], int n, int exp) {
int output[n];
int i, count[10] = { 0 };
for (i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
for (i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
for (i = 0; i < n; i++)
arr[i] = output[i];
}
void radixSort(int arr[], int n) {
int m = getMax(arr, n);
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, n, exp);
}
int update(int idx, int y) {
a[idx] = y;
int b[n];
for (int i = 0; i < n; i++) b[i] = a[i];
radixSort(b, n);
int ans = 0;
for (int i = 0; i < n;) {
ans++;
bool done = false;
for (int j = i + 1; j < n; j++) {
if (b[j] - b[i] > l) {
done = true;
i = j; break;
} else if (j == n - 1) {
i = n;
done = true;
}
}
if (!done) i++;
}
return ans;
}
int main() {
int x[] = {10, 15, 17, 20};
init(4, 10, x);
cout << update(2, 16) << endl;
}