Official

A - Streamer Takahashi Editorial by en_translator


For beginners

Person \(i\) can watch Takahashi’s stream for beginning to end only if the following two conditions are met:

  • Person \(i\) can start watching on or before \(L\) o’clock.
  • Person \(i\) can finish watching on or after \(R\) o’clock.

These can be expressed mathematically as \(X_i\leq L\) and \(R\leq Y_i\). All that left is to count the number of indices \(i\) satisfying them.

Sample code (Python)

N, L, R = map(int, input().split())
ans = 0
for i in range(N):
    x, y = map(int, input().split())
    if x <= L and R <= y:
        ans += 1

print(ans)

Sample code(c++)

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, L, R, ans = 0;
  cin >> N >> L >> R;
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    if (X <= L && R <= Y) ans++;
  }
  cout << ans << endl;
}

posted:
last update: