#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
const int oo = 1e9 + 7;
int N, arr[100001][2];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N;
for(int l = 0; l < N; l++)
cin >> arr[l][0] >> arr[l][1];
int lo = 0, hi = 100001, res = oo * oo;
while(lo <= hi) {
int md = (lo + hi) / 2;
bool ok = 1; int ans = 0;
vector<int> st(100001, 0);
for(int l = N - 1; l >= 0 && ok; l--) {
int curr = 0; vector<ii> vec;
for(int i = 0; i < arr[l][0]; i++)
vec.pb({st[i], i});
sort(all(vec));
for(int i = 0; i < arr[l][1]; i++) {
if(vec[i].ff > md) { ok = 0; break; }
ans += st[vec[i].ss]; st[vec[i].ss]++;
}
}
/// cout << ans << " " << md << "\n";
if(ok) res = min(res, ans), hi = md - 1;
else lo = md + 1;
}
cout << res << "\n";
}
Compilation message
sails.cpp: In function 'int32_t main()':
sails.cpp:34:25: warning: unused variable 'curr' [-Wunused-variable]
34 | int curr = 0; vector<ii> vec;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
1244 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
2284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
2628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
3956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1046 ms |
6248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
6128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
6284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |