Jim and the Orders

  • + 0 comments

    C++

     bool cmp(pair<int, int> a, pair<int, int> b)
     {
        if(a.first == b.first) return a.second < b.second;
        return a.first < b.first;
     }
    
    vector<int> jimOrders(vector<vector<int>> orders) {
        vector<pair<int, int>> vp; 
    		//first: serve time, second: *th-customer
        int n =  orders.size();
        for(int i = 0; i < n; i++){
            vp.push_back(make_pair(orders[i][0] + orders[i][1], i));
        }
        sort(vp.begin(), vp.end(), cmp);
        vector<int> ans;
        for(int i = 0; i < n; i++){
            ans.push_back(vp[i].second + 1);
        }
        return ans;
    }