Submission #739600

#TimeUsernameProblemLanguageResultExecution timeMemory
739600Dan4LifeHiring (IOI09_hiring)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mxN = (int)5e5+10;
const int mxC = (int)20010;
const int LINF = (int)1e18;
int n, W, baseS, S[mxN], Q[mxN];
int segTree[2*mxC], total[2*mxC];

void upd(int x, int v, int p=0, int l=1, int r=mxC){
    if(l==r){ segTree[p]+=v*l; total[p]+=v; return; }
    int mid = (l+r)/2; int rp = p+2*(mid-l+1);
    if(x<=mid) upd(x,v,p+1,l,mid);
    else upd(x,v,rp,mid+1,r);
    segTree[p] = segTree[p+1]+segTree[rp];
    total[p] = total[p+1]+total[rp];
}

int findNum(int x, int p=0, int l=1, int r=mxC){
    if(l==r){
        int L = 0, R = total[p];
        while(L<R){
            int mid = (L+R+1)/2;
            if(baseS*mid*l<=x)L=mid;
            else R=mid-1;
        }
        return L;
    }
    int mid = (l+r)/2; int rp = p+2*(mid-l+1);
    if(baseS*segTree[p]<=x) return total[p];
    if(baseS*segTree[p+1]==x) return total[p+1];
    if(baseS*segTree[p+1]>x) return findNum(x,p+1,l,mid);
    return total[p+1]+findNum(x-baseS*segTree[p+1],rp,mid+1,r);
}

int findSum(int x, int p=0, int l=1, int r=mxC){
    if(l==r) return x*l;
    int mid = (l+r)/2; int rp = p+2*(mid-l+1);
    if(total[p]<=x) return segTree[p];
    if(total[p+1]==x) return segTree[p+1];
    if(total[p+1]>x) return findSum(x,p+1,l,mid);
    return segTree[p+1]+findSum(x-total[p+1],rp,mid+1,r);
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> W;
    for(int i = 0; i < n; i++) cin >> S[i] >> Q[i];
    vector<int> ord(n,0); iota(all(ord),0);
    sort(all(ord),[&](int i, int j){
        return S[i]*Q[j] > S[j]*Q[i];
    });
    for(auto i : ord) upd(Q[i],1);
    int ans = 0, Num = 0, Den = 1, ind = -1, tot;
    for(auto i : ord){
        upd(Q[i],-1), tot = W*Q[i]; baseS = S[i];
        int cnt = findNum(tot)+1;
        int num = tot-baseS*(findSum(cnt-1)+Q[i]);
        cout << cnt << " " << num << " " << tot << "\n";
        if(num<cnt or (num==cnt and Num*tot=num*Den)
            ans=cnt,Num=num,Den=tot, ind=i;
    }
    if(ind==-1){cout<<0<<"\n";return 0;}
    vector<int> v;
    multiset<pair<int,int>> S;
    for(auto i : ord){
        if(i==ind){
            reverse(all(ord));
            for(auto j : ord){
                if(j==i) break;
                S.insert({Q[j],j});
            }
            int xd = ans-1; v.pb(i);
            while(xd--){
                v.pb(S.begin()->second);
                S.erase(S.begin());
            }
            break;
        }
    }
    cout << sz(v) << "\n"; sort(all(v));
    for(auto u : v) cout << u+1 << "\n";
}

Compilation message (stderr)

hiring.cpp: In function 'int32_t main()':
hiring.cpp:64:40: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   64 |         if(num<cnt or (num==cnt and Num*tot=num*Den)
      |                                     ~~~^~~~
hiring.cpp:64:33: error: lvalue required as left operand of assignment
   64 |         if(num<cnt or (num==cnt and Num*tot=num*Den)
      |                        ~~~~~~~~~^~~~~~~~~~~
hiring.cpp:66:5: error: expected primary-expression before '}' token
   66 |     }
      |     ^
hiring.cpp:65:44: error: expected ')' before '}' token
   65 |             ans=cnt,Num=num,Den=tot, ind=i;
      |                                            ^
      |                                            )
   66 |     }
      |     ~                                       
hiring.cpp:64:11: note: to match this '('
   64 |         if(num<cnt or (num==cnt and Num*tot=num*Den)
      |           ^
hiring.cpp:66:5: error: expected primary-expression before '}' token
   66 |     }
      |     ^