#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
// #define s second
#define pb(x) push_back(x)
#define int long long
/*
ORDERED SET PDBS
#include <bits/extc++.h>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
const int MOD = 1e9+7;
const int inf = 1e9;
const int INF = 1e18+20;
const int LOG = 25;
/*
n<=16, so you can stimulate to either give or not give the
book to each person and take minimum that satisfies
*/
int n;
vector<pair<int, int>> a;
vector<pair<int, int>> given;
int cnt=0;
int ans = inf;
void f (int i) {
if (i==n) {
int reached=0;
vector<int> tt(n, 0);
for (auto x:given) {
for (int i=0;i<n; i++) {
if (abs(x.first - a[i].first) <= x.second - a[i].second && !tt[i]) {
reached++;
tt[i]=1;
}
}
}
if (reached==n) {
ans=min(ans, cnt);
}
return;
}
// donate the book to this guy
given.push_back(a[i]);
cnt++;
f(i+1);
given.pop_back();
cnt--;
// do not donate the book to this guy
f(i+1);
}
void solve() {
cin>>n;
a.resize(n);
for (int i=0; i<n; i++) {
cin>>a[i].first>>a[i].second;
}
f(0);
cout<<ans<<endl;
}
bool multi=false;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
if (multi) cin>>t;
while (t--) solve();
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... |