Submission #886720

#TimeUsernameProblemLanguageResultExecution timeMemory
886720vjudge1San (COCI17_san)C++17
0 / 120
243 ms3524 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define ONLINE_JUDGE void solve() { int n; i64 k; cin >> n >> k; vector <int> h(n), g(n); for(int i = 0; i < n; i++) { cin >> h[i] >> g[i]; } vector <int> idxs[n + 2]; int half = n / 2; i64 ans = 0; for(int mask = 1; mask < (1 << half); mask++) { int last = 0, lst = -1; i64 sum = 0; bool ok = true; for(int i = 0; i < half; i++) { if(mask & (1 << i)) { if(h[i] < last) { ok = false; break; } last = h[i]; sum += g[i]; lst = i; } } if(ok) { idxs[lst].emplace_back(sum); ans += (sum >= k); } } for(int mask = 1; mask < (1 << (n - half)); mask++) { int last = 0, fir = -1; i64 sum = 0; bool ok = true; for(int i = 0; i < (n - half); i++) { if(mask & (1 << i)) { if(h[i + half] < last) { ok = false; break; } last = h[i + half]; sum += g[i + half]; if(fir == -1) { fir = half + i; } } } if(ok) { idxs[fir].emplace_back(sum); ans += (sum >= k); } } for(int i = 0; i < n; i++) { sort(idxs[i].begin(), idxs[i].end()); /* cerr << i << ": "; for(int &j : idxs[i]) { cerr << j << " "; } cerr << "\n"; */ } for(int i = 0; i < half; i++) { for(int &j : idxs[i]) { for(int l = half; l < n; l++) { if(h[i] < h[l]) { auto it = lower_bound(idxs[l].begin(), idxs[l].end(), k - j); ans += idxs[l].end() - it; } } } } cout << ans; return; } signed main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...