1
2
3
4
5
6
7
8
9
10
11
12
13
| void solve() {
auto [n, x, y] = read<int, i64, i64>();
auto a = read_vec<int>(n);
i64 sum = accumulate(a.begin(), a.end(), zero);
auto count = [&a](i64 l, i64 r) {
i64 cnt = 0;
for (int i = 0; i < a.size(); i ++) {
cnt += upper_bound(a.begin() + i + 1, a.end(), r - a[i]) - lower_bound(a.begin() + i + 1, a.end(), l - a[i]);
}
return cnt;
};
cout << count(max(zero, sum - y), sum - x) << "\n";
}
|