Digikala plans to implement its new product n n Applicant software engineer, max k…
- User
Digikala plans to implement its new product n n Applicant software engineer, max k choose k people, so that the "coolness" number of the team is maximized. In the interview process, for each person, a measure of "well-being" and a measure of "well-being" are calculated. The number of "coolness" of the selected team is equal to the product of the sum of morals of the team members and the minimum of the pleasantness of the team members. With a list of good numbers of engineers applying, determine what the coolest team score is.
input The input consists of three lines. In the first line of the number n n means the total number, in the second line the morals of the people with a distance from each other and in the third line the auspiciousness of the people with a distance and finally the number of people needed k k. 1 ≤ k ≤ n ≤ 100
00 1≤k≤n≤100 00 1 ≤ M a r a m ≤ 100
000 1≤Maram≤100 000 1 ≤ K h O s h M a s h r e b i ≤ 1 0 8 1≤KhoshMashrebi≤10 8
output The output is an integer representing the remainder of the score of the coolest possible team of 7 + 9^10.
Example Sample input 1 6 2 10 3 1 5 8 5 4 3 9 7 2 3 Plain text Sample output 1 68 Plain text In this example, the coolest team is for the case where the subset of people whose morals are 2, 10, and 5 is selected, and in this case, the coolness score of the team is equal to the product of the sum of the said numbers (17) and the minimum of being good like them (4). is So the total coolness score is 68.
Sample input 2 6 2 10 3 1 5 8 5 4 3 9 7 2 4 Plain text Sample output 2 72 write in c++
- Assistant
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> maram(n); for(int i=0;i<n;i++) cin >> maram[i]; vector<ll> khosh(n); for(int i=0;i<n;i++) cin >> khosh[i]; int k; cin >> k; // Create list of people vector<pair<ll, ll>> people(n); for(int i=0;i<n;i++) { people[i] = {khosh[i], maram[i]}; } // Sort descending by khosh sort(people.begin(), people.end(), [&](const pair<ll, ll> &a, const pair<ll, ll> &b) -> bool{ if(a.first != b.first) return a.first > b.first; return a.second > b.second; }); // Min heap for maram priority_queue<ll, vector<ll>, std::greater<ll>> pq; ll sum =0; ll max_coolness =0; // Define modulo ll modulo = 3486784408LL; for(int i=0;i<n;i++){ ll current_maram = people[i].second; ll current_khosh = people[i].first; pq.push(current_maram); sum += current_maram; if((int)pq.size() > k){ sum -= pq.top(); pq.pop(); } if((int)pq.size() == k){ ll coolness = sum * current_khosh; if(coolness > max_coolness){ max_coolness = coolness; } } } cout << (max_coolness % modulo); }