답안 #4111

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

typedef long long ll;

using namespace std;

int P, N;
pair<int,ll> solve(const vector<int>& p) {
	int cnt = -1, st = 0;
	while (st + p[cnt+1] < P) {
		st += p[cnt+1];
		cnt++;
	}
	cnt += 1;
	int extra = P - st - 1;
	int sum = 0;
	for (int i = 0; i < cnt; ++i) {
		sum += (cnt-i) * p[cnt-i-1];
	}
	return make_pair(cnt, sum + extra * cnt);
}

int main() {
	scanf("%d%d", &P, &N);
	vector<int> penalty(N, 0);
	for (int i = 0; i < N; ++i)
		scanf("%d", &penalty[i]);
	sort(penalty.begin(), penalty.end());
	pair<int,ll> res = solve(penalty);
	printf("%d %lld\n", res.first, res.second);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Correct 0 ms 1236 KB Output is correct
4 Correct 4 ms 1236 KB Output is correct
5 Correct 0 ms 1236 KB Output is correct
6 Correct 4 ms 1236 KB Output is correct
7 Correct 4 ms 1408 KB Output is correct
8 Correct 8 ms 1428 KB Output is correct
9 Incorrect 20 ms 1624 KB Output isn't correct
10 Halted 0 ms 0 KB -