-
Notifications
You must be signed in to change notification settings - Fork 0
/
shopaholic.cpp
48 lines (38 loc) · 929 Bytes
/
shopaholic.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @file shopaholic.cpp
* @author William Weston
* @brief Shopaholic Problem From Kattis
* @version 0.1
* @date 2023-07-17
*
* @copyright Copyright (c) 2023
*
* Source: https://open.kattis.com/problems/shopaholic
*/
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
auto main() -> int
{
for ( int n; std::cin >> n; )
{
auto prices = std::vector<int>();
prices.reserve( n );
for ( int price; n--; )
{
std::cin >> price;
prices.push_back( price );
}
std::sort( prices.begin(), prices.end(), std::greater{} );
auto const sz = prices.size();
auto total_discount = 0ll;
for ( std::vector<int>::size_type idx = 2; idx < sz; idx += 3 )
{
total_discount += prices[idx];
}
std::cout << total_discount << '\n';
}
return EXIT_SUCCESS;
}