-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCARSELL.cpp
34 lines (33 loc) · 902 Bytes
/
CARSELL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
// your code goes here
ll t;
//Number of test cases
cin >> t;
ll mod = 1000 * 1000 * 1000 + 7;
while(t--) {
//Input number of years
ll n;
cin >> n;
//Price of cars
vector<ll> num(n);
for (ll i = 0;i < n;i++) {
cin >> num[i];
}
//Sort the prices in descending order (greater<ll>() is a standard function in STL
//which sorts in descending order)
sort(num.begin(),num.end(),greater<ll>());
//Maximum profit variable
ll sum = 0;
//Here, i represents number of years. The obvious way to maximise the price is take the
//largest price first and then add it to the profilt variable
for (ll i = 0;i < n;i++) {
sum = (sum + max((ll)0,num[i] - i)) % mod;
}
//Output profit
cout << sum << "\n";
}
return 0;
}