Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;
}
posted on 2015-05-26 14:16  Tonix  阅读(154)  评论(0)    收藏  举报