#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 100'000;
int n;
pair<int,int> mast[max_n];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++)
cin >> mast[i].first >> mast[i].second;
sort(mast, mast + n);
set<pair<int,int>> H;
unordered_map<int,int> cnt;
for (int h = 1; h <= mast[n - 1].first; h++)
{
cnt[h] = 0;
H.insert({cnt[h], h});
}
for (int i = 0; i < n; i++)
{
vector<pair<int,int>> best;
for (auto [count, height] : H)
if (best.size() >= mast[i].second)
break;
else if (height <= mast[i].first)
best.push_back({count, height});
for (auto [count, height] : best)
{
H.erase({count, height});
H.insert({count + 1, height});
cnt[height] = count + 1;
}
}
ll sum = 0;
for (auto [count, height] : H)
sum += count * (count - 1) / 2;
cout << sum << '\n';
return 0;
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:35:29: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if (best.size() >= mast[i].second)
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
24 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
747 ms |
768 KB |
Output is correct |
2 |
Execution timed out |
1025 ms |
9804 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1045 ms |
3464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
3712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1079 ms |
5888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1025 ms |
12808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
11384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1080 ms |
11560 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |