Submission #1011156

#TimeUsernameProblemLanguageResultExecution timeMemory
1011156GrindMachineHiring (IOI09_hiring)C++17
30 / 100
409 ms55488 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif /* */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; template<typename T> struct fenwick { int n; vector<T> tr; int LOG = 0; fenwick() { } fenwick(int n_) { n = n_; tr = vector<T>(n + 1); while((1<<LOG) <= n) LOG++; } int lsb(int x) { return x & -x; } void pupd(int i, T v) { for(; i <= n; i += lsb(i)){ tr[i] += v; } } T sum(int i) { T res = 0; for(; i; i ^= lsb(i)){ res += tr[i]; } return res; } T query(int l, int r) { if (l > r) return 0; T res = sum(r) - sum(l - 1); return res; } int lower_bound(T s){ // first pos with sum >= s if(sum(n) < s) return n+1; int i = 0; rev(bit,20-1,0){ int j = i+(1<<bit); if(j > n) conts; if(tr[j] < s){ s -= tr[j]; i = j; } } return i+1; } int upper_bound(T s){ return lower_bound(s+1); } }; void solve(int test_case) { ll n,m; cin >> n >> m; vector<pll> a(n); rep(i,n) cin >> a[i].ff >> a[i].ss; map<pll,vector<ll>> mp; rev(i,n-1,0) mp[a[i]].pb(i); auto cmp = [&](pll &p1, pll &p2){ auto [s1,q1] = p1; auto [s2,q2] = p2; // s1/q1 < s2/q2? // s1*q2 < s2*q1? return s1*q2 < s2*q1; }; sort(all(a),cmp); vector<ll> b; rep(i,n) b.pb(a[i].ss); b.pb(-1); sort(all(b)); b.resize(unique(all(b))-b.begin()); ll siz = sz(b); fenwick<ll> fenw_cnt(siz+5), fenw_sum(siz+5); ll ans = 0; rep(i,n){ ll ind = lower_bound(all(b),a[i].ss)-b.begin(); fenw_cnt.pupd(ind,1); fenw_sum.pupd(ind,a[i].ss); ll mx_sum = m*a[i].ss/a[i].ff; ll mx_ind = fenw_sum.upper_bound(mx_sum)-1; ll sum = fenw_sum.query(1,mx_ind); ll cnt = fenw_cnt.query(1,mx_ind); amax(ans,cnt); } cout << ans << endl; rep1(i,ans) cout << i << endl; } int main() { fastio; int t = 1; // cin >> t; rep1(i, t) { solve(i); } return 0; }

Compilation message (stderr)

hiring.cpp: In function 'void solve(int)':
hiring.cpp:156:12: warning: unused variable 'sum' [-Wunused-variable]
  156 |         ll sum = fenw_sum.query(1,mx_ind);
      |            ^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...