답안 #3627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3627 2013-08-31T07:05:47 Z MiNu King of penalty (kriii1_K) C++
1 / 1
24 ms 1936 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int n, p;
    scanf("%d %d", &p, &n);

    int t[n+1];
    int s = 0;
    for ( int i=0 ; i<n ; ++i )
    {
        scanf("%d", &t[i]);
    }
    sort(t, t+n);

    int k = 0;
    for ( int i=0 ; i<n ; ++i )
    {
        if ( s + t[i] < p )
        {
            s += t[i];
            ++k;
        }
        else 
        {
            k = i;
            break;
        }
    }

    int e = p - s - 1;
    long long total = 0LL;
    for ( int i=k-1 ; i>=0 ; --i )
    {
        e += t[i];
        total += e;
    }

    cout << k << " " << total << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1672 KB Output is correct
2 Correct 0 ms 1672 KB Output is correct
3 Correct 0 ms 1672 KB Output is correct
4 Correct 4 ms 1672 KB Output is correct
5 Correct 0 ms 1672 KB Output is correct
6 Correct 4 ms 1672 KB Output is correct
7 Correct 8 ms 1716 KB Output is correct
8 Correct 8 ms 1740 KB Output is correct
9 Correct 24 ms 1932 KB Output is correct
10 Correct 16 ms 1916 KB Output is correct
11 Correct 16 ms 1936 KB Output is correct
12 Correct 8 ms 1912 KB Output is correct
13 Correct 0 ms 1672 KB Output is correct
14 Correct 0 ms 1672 KB Output is correct
15 Correct 12 ms 1924 KB Output is correct