playground updated

This commit is contained in:
Hizenberg469
2024-11-30 23:25:28 +05:30
parent 9415c7f0c7
commit b46c486580
20 changed files with 837 additions and 566 deletions

View File

@@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 9;
int n, k, h;
int need = int(1e9);
int cnt[N];
int main() {
scanf("%d %d", &n, &k);
for(int i = 0; i < n; ++i){
int x;
scanf("%d", &x);
h = max(h, x);
need = min(need, x);
++cnt[x];
}
int pos = N - 1;
int res = 0;
long long sum = 0;
int c = 0;
while(true){
long long x = sum - c * 1LL * (pos - 1);
if(x > k){
++res;
h = pos;
sum = pos * 1LL * c;
}
--pos;
if(pos == need) break;
c += cnt[pos];
sum += cnt[pos] * 1LL * pos;
}
if(h != need) ++res;
cout << res << endl;
}

View File

@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;
int rnd(int a,int b){
return a + rand() % ( b - a + 1 );
}
int main(int argc, char* argv[]){
int seed = atoi(argv[1]);
srand(seed);
int n = rnd(1,20);
int k = rnd(20, 40);
cout << n << ' ' << k << '\n';
int val = 0;
for(int i = 0 ; i < n ; i++ ){
val = rnd(0,50);
cout << val << ' ';
}
cout << '\n';
return 0;
}