#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 40 + 100;
ll h[N], g[N], ans = 0, n, k;
vector <ll> lst[N];
vector <int> ed[N];
void dfs(int cur, int st, ll sum) {
lst[st].pb(sum);
if (sum >= k) {
ans++;
}
for (auto x : ed[cur]) {
dfs(x, st, sum + g[x]);
}
}
ll cal(int a, int b) {
ll ans = 0;
for (auto x : lst[a]) {
ll t = lower_bound(all(lst[b]), k - x) - lst[b].begin();
ans += (sz(lst[b]) - t);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> h[i] >> g[i];
}
int m = n / 2;
for (int i = 1; i <= m; i++) {
for (int j = i + 1; j <= m; j++) {
if (h[j] >= h[i]) {
ed[j].pb(i);
}
}
}
for (int i = m + 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (h[j] >= h[i]) {
ed[i].pb(j);
}
}
}
for (int i = 1; i <= n; i++) {
dfs(i, i, g[i]);
}
for (int i = 1; i <= m; i++) {
for (int j = m + 1; j <= n; j++) {
if (h[j] >= h[i]) {
ans += cal(i, j);
}
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
6668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |