Skip to content

Instantly share code, notes, and snippets.

@danicat
Created January 6, 2014 15:01
Show Gist options
  • Save danicat/8284005 to your computer and use it in GitHub Desktop.
Save danicat/8284005 to your computer and use it in GitHub Desktop.
TopCoder SRM 502 Division 2 250 pts.
#include <vector>
#include <algorithm>
using namespace std;
class TheProgrammingContestDivTwo {
public:
vector<int> find(int T, vector<int> requiredTime) {
vector<int> res;
int solved = 0;
int penalty = 0;
int remaining = T;
int elapsed = 0;
sort(requiredTime.begin(), requiredTime.end());
for(auto p : requiredTime) {
if( p <= remaining ) {
remaining -= p;
solved++;
penalty += elapsed += p;
}
}
res.push_back(solved);
res.push_back(penalty);
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment