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
#include <iostream>
#include <algorithm>

constexpr int p = 1e9 + 7;

int totals[5001] = { 0 };
int vals[5001];

int main() {
  int n;
  std::cin >> n;
  totals[0] = 1;
  for (int i = 0; i < n; i++) {
    std::cin >> vals[i];
  }
  std::sort(vals, vals + n);
  int max = 0;
  for (int i = 0; i < n; i++) {
    int min = vals[i] - 1;
    for (int j = max; j >= min; j--) {
      int target = std::min(5000, j + vals[i]);
      totals[target] = (totals[target] + totals[j]) % p;
    }
    if (max >= min) {
      max = std::min(max + vals[i], 5000);
    }
  }

  int total = 0;
  for (int i = 1; i <= 5000; i++) {
    total += totals[i];
    total %= p;
  }

  std::cout << total;

  return 0;
}