Joey loves to eat Pizza. But he is worried as the quality of pizza made by most of the restaurants is deteriorating. The last few pizzas ordered by him did not taste good :(. Joey is feeling extremely hungry and wants to eat pizza. But he is confused about the restaurant from where he should order. As always he asks Chandler for help.
Chandler suggests that Joey should give each restaurant some points, and then choose the restaurant having maximum points. If more than one restaurant has the same points, Joey can choose the one with the lexicographically smallest name.
Joey has assigned points to all the restaurants, but can't figure out which restaurant satisfies Chandler's criteria. Can you help him out?
Example:
Input: n=2, v={{108,"Pizzeria"},{145,"Dominos"},{49,"Pizzapizza"}}
Output: Dominos
Approach
C++
#include <bits/stdc++.h>using namespace std;bool cmp(pair<int, string> a, pair<int, string> b){if (a.first == b.first)return a.second > b.second;return a.first < b.first;}string pizzaConfusion(vector<pair<int, string>> &v, int n){sort(v.begin(), v.end(), cmp);return v[n - 1].second;}int main(){int n = 3;vector<pair<int, string>> v = {{108, "Pizzeria"},{145, "Dominos"},{49, "Pizzapizza"}};cout << pizzaConfusion(v, n) << "\n";return 0;}
No comments:
Post a Comment