1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdio>
#include <climits>

int n, c[1000010], d[1000010], maxk[1000010], poss[1000010];

int main() {
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d",&c[i],&d[i]);
  }
  maxk[n] = 0;
  poss[n] = 1;
  for (int i = n-1; i >= 0; i--) {
    int maxc = 0;
    int mind = INT_MAX;
    for (int j = i+1; j <= n; j++) {
      maxc = maxc > c[j-1] ? maxc : c[j-1];
      mind = mind < d[j-1] ? mind : d[j-1];
      if (j-i >= maxc && j-i <= mind) {
        if (maxk[i] < maxk[j]) {
          maxk[i] = maxk[j];
          poss[i] = poss[j];
        }
        else if (maxk[i] == maxk[j]) {
          poss[i] += poss[j];
          poss[i] %= 1000000007;
        }
      }
    }
    if (poss[i]) maxk[i]++;
  }


  if (poss[0]) {
    printf("%d %d\n",maxk[0],poss[0]);
  }
  else
  {
    printf("NIE\n");
  }
}