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>
using namespace std;
const int nmax = 500005;
int n, a[nmax], sol[nmax], mini = INT_MAX, fr[nmax], rasp[nmax];
pair<int, int> v[nmax];
bool verif(int k)
{
for(int i = 1; i <= n; i ++)
rasp[i] = 0;
for(int i = 1; i <= k; i ++)
for(int j = 1; j <= n; j ++)
if(abs(v[sol[i]].first - v[j].first) <= v[sol[i]].second - v[j].second)
rasp[j] = 1;
int ok = 1;
for(int i = 1; i <= n; i ++)
if(!rasp[i])
ok = 0;
return (ok);
}
void backy(int poz, int k, int &p)
{
if(poz > k)
{
if(verif(k))
{
p = 1;
return;
}
}
else
{
for(int i = 1; i <= n; i ++)
if(!fr[i])
{
fr[i] = 1;
sol[poz] = i;
backy(poz + 1, k, p);
fr[i] = 0;
}
}
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> v[i].first >> v[i].second;
int st = 1, dr = n;
while(st < dr)
{
int mij = (st + dr) / 2;
int p = 0;
backy(1, mij, p);
if(p)
{
dr = mij - 1;
mini = min(mini, mij);
}
else
st = mij + 1;
}
cout << mini;
return 0;
}
# | 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... |