Submission #886705

#TimeUsernameProblemLanguageResultExecution timeMemory
886705vjudge1San (COCI17_san)C++17
0 / 120
693 ms25820 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define sp << " " << #define int long long #define vi vector<int> #define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++) #define pii pair<int,int> #define pb push_back typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 5e5+1; const int inf = 1e9+1; void solve() { int n,k; cin >> n >> k; vi h(n+1),g(n+1); F(i,n) cin >> h[i] >> g[i]; int n1 = n-n/2,n2 = n/2; int lim = (1<<n2); vi sm(lim); ordered_set ss[n2+1]; int ans = 0; for (int i=0;i<lim;i++) { int smm = 0; int prev = 0,first=0; bool cool = 1; for (int j=0;j<n2;j++) { if (i&(1<<j)) { if (h[n1+j+1] < prev) { cool = 0; break; } if (!first) first = j+1; prev = h[n1+j+1]; smm+=g[n1+j+1]; } } if (cool) { if (smm >= k) { ans++; cout << i sp smm << endl; } ss[first].insert(smm); } } lim = (1<<n1); for (int i=1;i<lim;i++) { int smm = 0,prev = 0; bool cool = 1; for (int j=0;j<n2;j++) { if (i&(1<<j)) { if (h[j+1] < prev) { cool = 0; break; } prev = h[j+1]; smm+=g[j+1]; } } if (!cool) continue; if (smm >= k) { ans++; } for (int j=1;j<=n2;j++) { if (h[n1+j] >= prev) ans+=ss[j].size()-ss[j].order_of_key(k-smm); } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen("in","r",stdin); freopen("out","w",stdout); #endif int t = 1; //cin >> t; F(i,t) solve(); }
#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...