Topcoder SRM145 Div1 Level 1 Bonuses

解法


問題文通りそれぞれの人のポイントの割合を求めた後,
あまった分をpointsの値の大きい人から足していく.
pointsの各値は1から500なので,2重ループにするとたぶん楽

std::accumulateを初めて使ってみた

コード


#include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

class Bonuses {
public:
  std::vector<int> getDivision(std::vector<int> points) {
    int total = std::accumulate(points.begin(), points.end(), 0);
    int n = points.size();
    int res[64];

    for(int i = 0; i < n; ++i) {
      res[i] = points[i] * 100 / total;
    }
    
    int remainder = 100 - std::accumulate(res, res + n, 0);
    for(int i = 500; i >= 0; --i) {
      for(int j = 0; j < n and 0 < remainder; ++j) {
        if( points[j] == i ) {
          res[j] += 1;
          remainder -= 1;
        }
      }
    }

    return std::vector<int>(res, res+n);
  }    
};