#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define int ll
#define uint ull
pair<int, int> prods[2000 + 5];
int n, k;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> prods[i].second >> prods[i].first;
sort(prods, prods + n);
vector<int> untake;
vector<int> possworsecosts;
int ans = 0;
int time = 1;
int bought = 0;
for (int i = 0; i < n; ++i) {
auto [timing, cost] = prods[i];
if (timing < time) {
if (untake.empty()) continue;
int expensive = -1;
int expensivei = 0;
for (int i = 0; i < untake.size(); ++i) {
possworsecosts.emplace_back(abs(cost - untake[i]));
if (untake[i] > expensive) {
expensive = untake[i];
expensivei = i;
}
}
if (cost >= expensive) continue;
else {
time--;
bought--;
ans -= expensive;
untake[expensivei] = untake.back();
untake.pop_back();
}
}
time++;
bought++;
ans += cost;
untake.emplace_back(cost);
}
cout << bought << ' ' << ans << '\n';
if (!possworsecosts.empty()) {
sort(possworsecosts.begin(), possworsecosts.end());
cout << bought << ' ' << ans + possworsecosts[0] << '\n';
}
else {
sort(untake.begin(), untake.end());
cout << bought - 1 << ' ' << ans - untake.back() << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |