# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
557426 | 600Mihnea | Road Construction (JOI21_road_construction) | C++17 | 10082 ms | 5092 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
bool home = 1;
using namespace std;
typedef long long ll;
const int N=250000+7;
struct T{
ll x;
ll y;
};
bool cmpTx(T a,T b) {
return a.x<b.x;
}
int n;
int k;
T a[N];
ll how_many_under(ll d) {
ll sol=0;
for (int i=1;i<=n;i++) {
for (int j=1;j<i;j++) {
ll dij=max(a[i].x-a[j].x,abs(a[i].y-a[j].y));
if(dij<=d){
sol++;
}
}
}
return sol;
}
signed main() {
#ifdef ONLINE_JUDGE
home = 0;
#endif
home=0;
if (home) {
freopen("I_am_iron_man", "r", stdin);
}
else {
ios::sync_with_stdio(0); cin.tie(0);
}
cin>>n>>k;
for (int i=1;i<=n;i++) {
int x,y;
cin>>x>>y;
a[i]={x+y, x-y};
}
sort(a+1,a+n+1,cmpTx);
ll low=0,high=(ll)1e10,sol=-1;
while (low<=high) {
ll mid=(low+high)/2;
if(how_many_under(mid)<=k) {
sol=mid;
low=mid+1;
}else{
high=mid-1;
}
}
vector<ll> v;
for (int i=1;i<=n;i++) {
for(int j=1;j<i;j++) {
ll dij=max(a[i].x-a[j].x,abs(a[i].y-a[j].y));
if(dij<=sol){
v.push_back(dij);
}
}
}
sort(v.begin(),v.end());
assert((int)v.size()<=k);
v.resize(k, sol+1);
for (auto &x: v) {
cout<<x<<"\n";
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |