#include<bits/stdc++.h>
using namespace std;
#define int long long
int N = 1<<20;
vector<int> bpro(2*N, 0);
vector<int> bmin(2*N, 0);
void update(int curr, int l, int r, int ll, int rr, int p)
{
if (l >= rr || r <= ll)
{
bpro[curr]+=p;
bmin[curr]+=p;
return;
}
if (l >= ll && r <= rr)
{
bpro[curr]+=p+1;
bmin[curr]+=p+1;
return;
}
p += bpro[curr];
bpro[curr] = 0;
int m = (l+r)/2;
update(curr*2, l, m, ll, rr, p);
update(curr*2+1, m, r, ll, rr, p);
bmin[curr] = min(bmin[curr*2], bmin[curr*2+1]);
}
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
cin >> n;
vector<vector<int>> height(1e6+1);
int left = 0;
int sol = 0;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
height[a].push_back(b);
left += b;
}
priority_queue<int, vector<int>, less<int>> pq;
for (int i = 1e6; i > 0; i--)
{
int h = bmin[i+N];
int curr = i+N;
while (curr>1)
{
curr/=2;
h+=bpro[curr];
}
int b = left/i;
h = b-h;
for (int ele:height[i]) pq.push(ele);
while (pq.size() && h)
{
update(1, 0, N, i+1-pq.top(), i+1, 0);
pq.pop();
h--;
}
// while (pq.size() && pq.top() == i)
{
//update(1, 0, N, i+1-pq.top(), i+1, 0);
//pq.pop();
}
h = bmin[i+N];
curr = i+N;
while (curr>1)
{
curr/=2;
h+=bpro[curr];
}
sol += (h*(h-1))/2;
left -= h;
}
cout << sol << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
56668 KB |
Output is correct |
2 |
Correct |
30 ms |
56664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
56664 KB |
Output is correct |
2 |
Incorrect |
30 ms |
56668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
56924 KB |
Output is correct |
2 |
Incorrect |
29 ms |
56668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
56776 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
56668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
56924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
57680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
87 ms |
57940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
92 ms |
58488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
102 ms |
58704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
118 ms |
59164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |