-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPricing.h
More file actions
35 lines (24 loc) · 745 Bytes
/
Copy pathPricing.h
File metadata and controls
35 lines (24 loc) · 745 Bytes
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
35
#ifndef TOPCODER_PRICING_H
#define TOPCODER_PRICING_H
#include <algorithm>
#include <vector>
class Pricing
{
public:
int maxSales(std::vector<int> price);
};
int Pricing::maxSales(std::vector<int> price)
{
std::sort(price.begin(), price.end());
int m = 0;
for (int g0 = 0; g0 < price.size(); ++g0)
for (int g1 = g0; g1 < price.size(); ++g1)
for (int g2 = g1; g2 < price.size(); ++g2)
for (int g3 = g2; g3 < price.size(); ++g3)
{
int calc = (g1 - g0) * price[g0] + (g2 - g1) * price[g1] + (g3 - g2) * price[g2] + (price.size() - g3) * price[g3];
m = std::max(m, calc);
}
return m;
}
#endif TOPCODER_PRICING_H