# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040258 | MarwenElarbi | Road Construction (JOI21_road_construction) | C++17 | 787 ms | 8652 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>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define pb push_back
#define fi first
#define se second
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main(){
optimise;
int n,k;
cin>>n>>k;
vector<pair<int,int>> tab(n);
for (int i = 0; i < n; ++i)
{
cin>>tab[i].fi>>tab[i].se;
}
sort(tab.begin(),tab.end());
priority_queue<int> pq;
for (int i = 0; i < n; ++i)
{
for (int j = i-1; j >= max(0,i-1000) ; j--)
{
int cur=abs(tab[i].fi-tab[j].fi)+abs(tab[i].se-tab[j].se);
if(pq.size()<k) pq.push(cur);
else{
if(pq.top()>cur){
pq.pop();
pq.push(cur);
}
}
}
}
vector<int> ans(k);
for (int i = 0; i < k; ++i)
{
ans[i]=pq.top();
pq.pop();
}
reverse(ans.begin(),ans.end());
for (int i = 0; i < k; ++i)
{
cout <<ans[i]<<endl;
}
}
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... |