Submission #12736

#TimeUsernameProblemLanguageResultExecution timeMemory
12736ainu7King of penalty (kriii1_K)C++98
1 / 1
68 ms2064 KiB
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int main()
{
  int P, N;
  cin >> P >> N;
  long long res = 0;
  int cnt = 0;
  vector<int> V(N);
  for (int i=0; i<N; i++)
    cin >> V[i];
  sort(V.begin(), V.end());

  P --;
  for (int i=0; i<N; i++) {
    if (P >= V[i]) {
      cnt ++;
      res += P;
      P -= V[i];
    }
  }
  cout << cnt << " " << res << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...