Submission #1157648

#TimeUsernameProblemLanguageResultExecution timeMemory
1157648fryingducAdvertisement 2 (JOI23_ho_t2)C++20
100 / 100
114 ms6308 KiB
#include "bits/stdc++.h"

using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif

const int maxn = 5e5 + 5;
int n, ord[maxn];
pair<int, int> a[maxn];

void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first >> a[i].second;
    ord[i] = i;
  }
  sort(ord + 1, ord + n + 1, [](const int &x, const int &y) -> bool {
    if (a[x].first + a[x].second == a[y].first + a[y].second) {
      return a[x].second - a[x].first < a[y].second - a[y].first;
    }
    return a[x].first + a[x].second < a[y].first + a[y].second;
  });
  int cnt = 0, mx = -1e9;
  for (int i = n; i; --i) {
    if (a[ord[i]].second - a[ord[i]].first > mx) {
      mx = a[ord[i]].second - a[ord[i]].first;
      ++cnt;
    }
  }
  cout << cnt;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  solve();

  return 0;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...