| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1340087 | asim | Dodatna (COCI25_dodatna) | C++20 | 1082 ms | 15704 KiB |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define endl "\n"
#define Yes cout << "YES" << endl;
#define No cout << "NO" << endl;
#define mod(a) ((a % MOD + MOD) % MOD)
#define inp(v) for(auto &a : v) cin >> a;
#define out(v) for(auto &a : v) cout << a << " ";
const int MOD = (int)1e9 + 7;
const int MAX = (int)1e5;
vector<pair<int, int>> vt;
bool check(int m, int k, int eded) {
int say = 0;
vector<pair<int, int>> mp;
int eded2 = LLONG_MAX;
eded = 0;
for(auto[l, r] : vt) {
if(r - l >= m) {
mp.pb({l, 1});
mp.pb({r - m + 1, -1});
eded = max(eded, r - m + 1);
eded2 = min(eded2, l);
}
}
sort(all(mp));
for(auto[l, r] : mp) {
say += r;
if(say >= k) {
return true;
}
}
return false;
}
void solve() {
//x >> y = x / (2 ^ y)
//x << y = x * (2 ^ y)
int n,k;
cin >> n >> k;
int eded = -1;
for(int i = 1; i <= n; i++) {
int x,y;
cin >> x >> y;
eded = max(eded, y);
vt.pb(make_pair(x, y));
}
if(k == 1) {
int ans = 0;
for(auto[l, r] : vt) {
ans = max(ans, r - l);
}
cout << ans << endl;
return;
}
int l = 0, r = eded;
int ans = 0;
while(l <= r) {
int m = l + (r - l) / 2;
if(check(m, k, eded)) {
l = m + 1;
ans = max(ans, m);
}
else {
r = m - 1;
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}Compilation message (stderr)
| # | 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... | ||||
