This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ft first
#define sd second
#define pb push_back
using namespace std;
typedef long long ll;
int n, h[40];
ll k, g[40], ans, f[40];
vector <int> gr[40];
void rec(int v, ll cr) {
if (cr >= k) {
ans += f[v];
return;
}
for (int u : gr[v])
rec(u, cr + g[u]);
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> h[i] >> g[i];
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (h[i] <= h[j])
gr[i].pb(j);
for (int i = n - 1; i >= 0; i--) {
f[i] = 1;
for (int j : gr[i])
f[i] += f[j];
}
for (int i = 0; i < n; i++)
rec(i, g[i]);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |