#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define pu push
#define ins insert
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fu(x,a,b) for (auto x=a;x<=b;x++)
#define fd(x,a,b) for (auto x=a;x>=b;x--)
#define int ll
using namespace std;
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
/*
Competitive Programming notes that I need to study & fix my dumbass self:
1. Coding:
- Always be sure to check the memory of arrays (maybe use vectors), for loops
- Always try to maximize the memory if possible, even if you are going for subtasks
- Do not exploit #define int long long, it will kill you
2. Stress:
- Always try generating big testcases and try if they run
3. Time management:
- Don't overcommit or undercommit, always spend a certain amount of time to think a problem, don't just look at it and say I'm fucked
- Do not spend too much time coding brute-force solutions, they should be easily-codable solutions that don't take up too much time
Time management schedule:
Offline / LAH days (4 problems - 3h):
15' thinking of solution / idea
1. no idea: skip
2. yes idea: continue thinking for <= 15'
+ implementing: <= 20'
+ brute-force: <= 5'
+ test generator: <= 5'
I hate offline because I am dumb
*/
typedef pair<int, int> ii;
const int N = 2e5+5;
const int B = 750;
const int mod = 1e9+7;
const int inf = 1e18;
using cd = complex<double>;
const long double PI = acos(-1);
int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;}
struct point {
int x,y;
bool operator < (const point& other) {
if (x == other.x) return y < other.y;
return x < other.x;
}
};
struct cmp {
bool operator() (const point& a, const point& b) const {
if (a.y != b.y) return a.y < b.y;
return a.x < b.x;
}
};
int n,k;
vector<point> a;
set<point, cmp> s;
vector<int> d;
int calc(int mid)
{
d.clear(); s.clear();
for (auto i : a)
{
int x = i.x, y = i.y;
// cout<<"Current point: "<<x<<" "<<y<<endl;
point cur = {-inf, y-mid};
while (true)
{
if (d.size() >= k) break;
auto it = s.upper_bound(cur);
if (it == s.end()) break;
cur = *it;
// cout<<cur.x<<" "<<cur.y<<endl;
if (cur.x < x-mid)
{
s.erase(it);
continue;
}
if (cur.y > y+mid) break;
// cout<<x<<" "<<cur.x<<" "<<y<<" "<<cur.y<<endl;
// cout<<endl;
d.pb(max(abs(x-cur.x), abs(y-cur.y)));
if (d.size() >= k) break;
}
if (d.size() >= k) break;
s.insert(i);
}
return d.size();
}
void solve()
{
cin>>n>>k;
for (int i = 0; i < n; i++) {
int x,y; cin>>x>>y;
a.pb({x+y,x-y});
}
sort(all(a));
// for (auto i : a) cout<<i.x<<" "<<i.y<<endl;
int l = 0, r = inf, res;
while (l <= r)
{
int mid = l+r>>1;
if (calc(mid) < k) l = mid+1, res = mid;
else r = mid-1;
}
// cout<<res<<endl;
calc(res);
sort(all(d));
while (d.size() < k) d.pb(res+1);
for (auto i : d) cout<<i<<endl;
}
/*
Go through the mistakes you usually make and revise your code, for god's sake...
*/
signed main()
{
bruh
//freopen("input.inp","r",stdin);
//freopen("output.inp","w",stdout);
int t = 1;
// cin>>t;
while (t--)
{
solve();
cout<<"\n";
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |