답안 #3501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3501 2013-08-31T06:12:31 Z solveit King of penalty (kriii1_K) C++
1 / 1
24 ms 2064 KB
#include <iostream>
#include <string>
#include <math.h>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;


int P, N, A[100005];
int main() {
    scanf("%d %d", &P, &N);
    for(int i = 1;i<=N;i++)
        scanf("%d",&A[i]);
    sort(A + 1, A + 1 + N);
    A[N + 1] = P;
    int S = 0;
    long long res = 0;
    for(int i = 1;i<=N + 1;i++) {
        if(S + A[i] >= P) {
            long long acc = 0;
            for(int j = i - 1;j>=1;j--) {
                acc += A[j];
                res += acc;
            }
            res += ((long long)(P - S - 1)) * (i - 1);
            printf("%d %lld\n", i - 1, res);
            return 0;
        }
        S += A[i];
    }
    printf("%d %d\n", 0, 0);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2064 KB Output is correct
2 Correct 0 ms 2064 KB Output is correct
3 Correct 0 ms 2064 KB Output is correct
4 Correct 4 ms 2064 KB Output is correct
5 Correct 0 ms 2064 KB Output is correct
6 Correct 4 ms 2064 KB Output is correct
7 Correct 4 ms 2064 KB Output is correct
8 Correct 8 ms 2064 KB Output is correct
9 Correct 16 ms 2064 KB Output is correct
10 Correct 24 ms 2064 KB Output is correct
11 Correct 16 ms 2064 KB Output is correct
12 Correct 12 ms 2064 KB Output is correct
13 Correct 0 ms 2064 KB Output is correct
14 Correct 0 ms 2064 KB Output is correct
15 Correct 12 ms 2064 KB Output is correct