#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
ll a[50], b[50], f[50], ans, n, m;
vector <ll> g[50], vr[50];
void dfs(int v, ll s)
{
s += b[v];
if (m <= s) {ans += f[v]; return;}
for (auto it : g[v])
{
dfs(it, s);
}
}
int main()
{
// freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
for (ll i = 0; i < n; i++)
for (ll j = i + 1; j < n; j++)
if (a[i] <= a[j])
{g[i].pb(j); vr[j].pb(i);}
for (ll i = n - 1; i >= 0; i--)
{
f[i]++;
for (auto it : vr[i])
f[it] += f[i];
}
for (int i = 0; i < n; i++) dfs(i, 0);
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
384 KB |
Output is correct |
2 |
Correct |
305 ms |
504 KB |
Output is correct |