-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTask H.cpp
More file actions
40 lines (35 loc) · 1.18 KB
/
Task H.cpp
File metadata and controls
40 lines (35 loc) · 1.18 KB
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
#include <iostream>
#include <vector> // vector
#include <algorithm> // sort
using namespace std;
void solve(){
int n, k;
vector <int> price;
cin >> n >> k;
int num;
int sum = 0;
// Просто заполняем цены.
for (int i = 0; i < n; i++){
cin >> num;
sum += num;
price.push_back(num);
}
// Производим сортировку (quick sort) и переворачиваем, чтобы цены были
// В порядке убывания т.к. по условию сказано, что персонаж захотел разбить товары
// По цене, чтобы добиться большей скидки. Логичнее идти от большего к меньшему.
sort(price.begin(), price.end());
reverse(price.begin(), price.end());
// Уменьшаем суммы покупки с учетом скидочного товара
for (int i = 1; i <= n; i++){
if (i % k == 0){
sum -= price[i - 1];
}
}
cout << sum;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}