답안 #4112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4112 2013-09-01T15:33:23 Z jays King of penalty (kriii1_K) C++
1 / 1
24 ms 1980 KB
#include <algorithm>
#include <cstdio>
#include <vector>

typedef long long ll;

using namespace std;

int P, N;
vector<int> pen;

ll solve(int n) {
	ll ret = 0;
	int cp = P - 1;
	for (int i = 0; i < n; ++i) {
		ret += cp;
		cp -= pen[i];
	}
	return ret;
}

int main() {
	scanf("%d%d", &P, &N);
	for (int i = 0; i < N; ++i) {
		int t; scanf("%d", &t);
		pen.push_back(t);	
	}
	sort(pen.begin(), pen.end());
	int sum = 0;
	for (int i = 0; i < pen.size(); ++i) {
		sum += pen[i];
		if (sum >= P) {
			printf("%d %lld\n", i, solve(i));
			return 0;
		}
	}
	printf("%d %lld\n", N, solve(N));
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1208 KB Output is correct
2 Correct 0 ms 1208 KB Output is correct
3 Correct 0 ms 1208 KB Output is correct
4 Correct 4 ms 1340 KB Output is correct
5 Correct 0 ms 1208 KB Output is correct
6 Correct 4 ms 1340 KB Output is correct
7 Correct 8 ms 1596 KB Output is correct
8 Correct 8 ms 1596 KB Output is correct
9 Correct 24 ms 1980 KB Output is correct
10 Correct 20 ms 1980 KB Output is correct
11 Correct 12 ms 1980 KB Output is correct
12 Correct 12 ms 1980 KB Output is correct
13 Correct 0 ms 1208 KB Output is correct
14 Correct 0 ms 1208 KB Output is correct
15 Correct 12 ms 1980 KB Output is correct