답안 #3531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3531 2013-08-31T06:25:08 Z eldkqmfhf123 King of penalty (kriii1_K) C++
1 / 1
68 ms 3112 KB
#include<iostream>
#include<algorithm>
using namespace std;

long long int Data[100010];
//long long int sum[100010];
int main()
{
	long long int n, m;
	cin >> m >> n;

	long long int i,j;
	long long int sum=0;
	for(i=0;i<n;i++)
	{
		cin >> Data[i];
		sum += Data[i];
	}

	std::sort(Data,Data+n);
	
	for(i=n;i>=1;i--)
	{
		if(sum >= m)
		{
			sum -= Data[i-1];
			continue;
		}
		long long int Arr[100010]={0,};
		Arr[0] = Data[i-1];
		long long int k = i-2;
		long long int sum2=Arr[0];
		for(j=1;j<i;j++)
		{
			Arr[j] = Arr[j-1] + Data[k];
			sum2 += Arr[j];
			k--;
		}

		long long int diff = m-Arr[i-1]-1;

		long long int ans=sum2;
		ans += (diff * i);
		cout << i << " "  << ans << endl;
		break;
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3108 KB Output is correct
2 Correct 0 ms 3108 KB Output is correct
3 Correct 0 ms 3108 KB Output is correct
4 Correct 8 ms 3108 KB Output is correct
5 Correct 0 ms 3112 KB Output is correct
6 Correct 8 ms 3108 KB Output is correct
7 Correct 24 ms 3108 KB Output is correct
8 Correct 28 ms 3108 KB Output is correct
9 Correct 64 ms 3108 KB Output is correct
10 Correct 68 ms 3112 KB Output is correct
11 Correct 32 ms 3104 KB Output is correct
12 Correct 24 ms 3108 KB Output is correct
13 Correct 0 ms 3108 KB Output is correct
14 Correct 4 ms 3104 KB Output is correct
15 Correct 16 ms 3104 KB Output is correct