kmjp's blog

競技プログラミング参加記です

TopCoder SRM 561 Div2 Easy FoxAndVacation

以前の解き残しを練習しておく。
ということでまずはSRM561 Div2 Easyから。
http://community.topcoder.com/stat?c=problem_statement&pm=11813

休暇の日数と、各街を訪れるのに必要な日数の入れるが与えられる。
休暇中に行ける最大の街の数を答える問題。

これはソートして必要な日数の少ない順に訪れるだけ。
Div2 Easyとはいええらく簡単だな…本番でもみんなかなりの速度で解いてるぞ。

class FoxAndVacation {
	public:
	int maxCities(int total, vector <int> d) {
		int i;
		sort(d.begin(),d.end());
		FOR(i,d.size()) {
			if(total<d[i]) return i;
			total -= d[i];
		}
		return i;
	}
};

*まとめ