#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve(){
int n; cin >> n;
int X[n + 1] = {}, E[n + 1] = {};
bool Sub1 = 1, Sub2 = (n <= 16);
for (int i = 1; i <= n; i++){
cin >> X[i] >> E[i];
if (i > 1 && E[i] != E[i - 1]) Sub1 = 0;
}
if (Sub1){
map<int, int> C;
int ans = 0;
for (int i = 1; i <= n; i++){
C[X[i]]++;
if (C[X[i]] == 1) ans++;
}
cout << ans << endl;
return;
}
else if (Sub2){
int ans = 16;
for (int i = 1; i <= (1LL << n); i++){
vector<int> x;
for (int j = 0; j < n; j++){
if ((i >> j) & 1) x.push_back(j + 1);
}
bool vis[n + 1] = {};
for (auto j : x){
for (int k = 1; k <= n; k++){
if (abs(X[k] - X[j]) <= E[j] - E[k]) vis[k] = 1;
}
}
int pos = 0;
for (int j = 1; j <= n; j++) pos += vis[j];
if (pos == n) ans = min(ans, (int)x.size());
}
cout << ans << endl;
return;
}
map<int, vector<int>> C;
int ans = 0;
vector<int> a;
for (int i = 1; i <= n; i++){
C[E[i]].push_back(i);
if (C[E[i]].size() == 1) a.push_back(E[i]);
}
int vis[n + 1] = {};
sort(rbegin(a), rend(a));
for (auto v : a){
for (auto i : C[v]){
for (int j = 1; j <= n; j++){
if (vis[j] == 1 && abs(X[j] - X[i]) <= E[j] - E[i]) vis[i] = 2;
}
if (vis[i] == 0){
vis[i] = 1;
ans++;
}
}
}
// for (int i = 1; i <= n; i++) cout << vis[i] << ' ';
// cout << endl;
cout << ans << endl;
}
signed main(){
int tc = 1;
// cin >> tc;
while (tc--){
solve();
}
}
| # | 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... |