标签:
Apparently, more expensive flowers should be bought with lower coeff. (Greedy part), and any unbalanced assignment would cause extra cost.
So the code would be:
#include<iostream> #include<algorithm> using namespace std; int main(void) { int N, K; cin >> N >> K; int C[N]; for(int i = 0; i < N; i++){ cin >> C[i]; } sort(C, C + N, greater<int>()); int result; int cnt = 0; for(int i = 0; i < N; i ++) result += C[i] * ((cnt ++) / K + 1); cout << result << "\n"; return 0; }
标签:
原文地址:http://www.cnblogs.com/tonix/p/4530539.html