# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
918018 |
2024-01-29T11:59:29 Z |
abczz |
Sails (IOI07_sails) |
C++14 |
|
63 ms |
5828 KB |
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#define ll long long
using namespace std;
bool ok;
vector <ll> V;
priority_queue<array<ll, 2>> pq;
ll n, a, b, k, l, r, z, mid, s, t, f, ps[100001], dlt[100001], cnt[100001];
int main() {
cin >> n;
for (int i=0; i<n; ++i) {
cin >> a >> b;
--a;
ps[a] += b;
t += b;
++cnt[a+1];
}
for (int i=1; i<100000; ++i) {
ps[i] += ps[i-1];
cnt[i] += cnt[i-1];
}
l = 0, r = n;
while (l < r) {
mid = (l+r)/2;
s = 0;
ok = 1;
for (int i=0; i<100000; ++i) {
s += min(n-cnt[i], mid);
if (s < ps[i]) {
ok = 0;
break;
}
}
if (ok) r = mid;
else l = mid+1;
}
for (int i=0; i<100000; ++i) {
s = min(n-cnt[i], l);
z += s;
dlt[i] = z-ps[i];
f += s * (s-1) / 2;
}
for (int i=99998; i>=0; --i) {
dlt[i] = min(dlt[i], dlt[i+1]);
}
for (int i=0; i<100000; ++i) {
pq.push({min(n-cnt[i], l), dlt[i]});
}
k = 0;
while (!pq.empty()) {
auto [w, u] = pq.top();
pq.pop();
if (u > k) {
f -= w-1;
++k;
pq.push({w-1, u});
}
}
cout << f << '\n';
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:56:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | auto [w, u] = pq.top();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4816 KB |
Output is correct |
2 |
Correct |
9 ms |
4816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4812 KB |
Output is correct |
2 |
Correct |
9 ms |
4816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4812 KB |
Output is correct |
2 |
Correct |
9 ms |
4812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
4812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4812 KB |
Output is correct |
2 |
Correct |
17 ms |
4812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
4816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
5828 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
4876 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
4804 KB |
Output is correct |
2 |
Correct |
44 ms |
4932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
4808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |