feat(priority-queue): new priority-queue problem formated

This commit is contained in:
2025-10-31 12:20:17 -03:00
parent 4aebd4c9db
commit 33df64c1c0
226 changed files with 6864 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, K;
cin >> N >> K;
// if one server can handle at least N clients then we just need one server
if (N <= K)
{
cout << "1" << endl;
return 0;
}
priority_queue<int> servers;
int size = 0;
while (N--)
{
int t;
cin >> t;
if (!servers.empty() && t - (-servers.top()) >= 1000)
{
servers.pop();
}
servers.push(-t);
size = max((int)servers.size(), size);
}
cout << ceil((double)size / K) << endl;
return 0;
}

View File

@@ -0,0 +1,19 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
setName("compare two signed int%d's", 8 * int(sizeof(int)));
registerTestlibCmd(argc, argv);
int ja = ans.readInt();
int pa = ouf.readInt();
if (ja != pa)
quitf(_wa, "expected %d, found %d", ja, pa);
quitf(_ok, "answer is %d", ja);
}

View File

@@ -0,0 +1,100 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 1;
const int MAX_N = 100000;
const int MIN_K = 1;
const int MAX_K = 100000;
const int MIN_TI = 0;
const int MAX_TI = 100000;
const int rnd_test_n = 100;
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
dest.insert(dest.end(), orig.begin(), orig.end());
}
string output_tc(int n, int k, const vector<int> &times) {
ostringstream oss;
oss << n << " " << k << endl;
for (int i = 0; i < n; i++) {
if (i != 0) oss << " ";
oss << times[i];
}
oss << endl;
return oss.str();
}
vector<string> generate_sample_tests() {
vector<string> tests;
tests.push_back(output_tc(2, 1, {0, 1000}));
tests.push_back(output_tc(3, 2, {1000, 1010, 1999}));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
tests.push_back(output_tc(5, 1, {1, 1, 1, 1, 1}));
tests.push_back(output_tc(1, 100000, {1}));
return tests;
}
string rnd_test(int i){
int min_n = MIN_N;
int max_n = MAX_N;
if(i<rnd_test_n / 3){
max_n = 1000;
}
else if(i<rnd_test_n / 2){
max_n = 10000;
}
int n = rnd.next(min_n, max_n);
int k = rnd.next(MIN_K, n);
vector<int> times(n);
for (int i = 0; i < n; i++) times[i] = rnd.next(MIN_TI, MAX_TI);
sort(times.begin(), times.end());
return(output_tc(n, k, times));
}
vector<string> generate_random_tests() {
vector<string> tests;
for (int i = 0; i < rnd_test_n; i++){
tests.push_back(rnd_test(i));
}
return tests;
}
string extreme_test_1(){
int n = MAX_N;
int k = MIN_K;
vector<int> times(n);
for (int i = 0; i < n; i++) times[i] = MAX_TI;
return(output_tc(n, k, times));
}
vector<string> generate_extreme_tests(){
vector<string> tests;
tests.push_back(extreme_test_1());
return tests;
}
int main(int argc, char *argv[]) {
registerGen(argc, argv, 1);
vector<string> tests;
size_t test = 0;
append(tests, generate_sample_tests());
append(tests, generate_manual_tests());
append(tests, generate_random_tests());
append(tests, generate_extreme_tests());
for (const auto &t : tests) {
startTest(++test);
cout << t;
}
return 0;
}

View File

@@ -0,0 +1 @@
generator

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
registerValidation(argc, argv);
int n = inf.readInt(1, 1e5, "n");
inf.readSpace();
inf.readInt(1, 1e5, "k");
inf.readEoln();
int lastTime = 0;
for (int i = 0; i < n; i++) {
if (i != 0) inf.readSpace();
int curTime = inf.readInt(0, 1e5, "ti");
ensuref(curTime >= lastTime, "Times must be in increasing order");
lastTime = curTime;
}
inf.readEoln();
inf.readEof();
return 0;
}