We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Greedy
- Jim and the Orders
- Discussions
Jim and the Orders
Jim and the Orders
+ 9 comments for those who got problem (simple method using multimap)
int main() {
multimap<int,int> m; int n;cin>>n; for(int i=1;i<=n;i++) { int a,b; cin>>a>>b; m.insert(make_pair(a+b,i)); } for(multimap<int,int >::iterator me=m.begin();me!=m.end();me++ ) {cout<<me->second<<" "; } return 0;
}
+ 10 comments getting same output as defined in test case 7 on my local pc it fails in hacker rank kindly help....
+ 1 comment How does this problem come under "greedy" paradigm?
+ 2 comments def jimOrders(orders): serve_time = []
for i, v in enumerate(orders): serve_time.append([v[0]+v[1],i+1]) serve_time.sort() order = [x[1] for x in serve_time] return order
my solution in python 3, pretty simple
+ 1 comment Satisfies "If two fans get the burger at the same time, then print the smallest numbered order first" without any extra condition.
vector<int> jimOrders(vector<vector<int>> orders) { int n=orders.size(); vector<pair<int,int>> sum(n); for(int i=0;i<n;i++) { sum[i].first=orders[i][0]+orders[i][1]; sum[i].second=i+1; } sort(sum.begin(), sum.end()); vector<int> index(n); for(int i=0;i<n;i++) { index[i]=sum[i].second; } return index; }
Load more conversations
Sort 454 Discussions, By:
Please Login in order to post a comment