fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. long long n,m,a[100001], somma = 0,i;
  8.  
  9. cin >> n >> m;
  10. for (int i=0; i<n; i++) {
  11. cin >> a[i];
  12. somma += a[i];
  13. }
  14. sort(a,a+n);
  15. i = 1;
  16. while (i*(i+1)/2 - somma < m) i++;
  17. cout << i << somma << a[0] << a[1] << a[2] << a[3];
  18. // your code goes here
  19. return 0;
  20. }
Success #stdin #stdout 0s 4956KB
stdin
4 14
4 6 12 8

stdout
93046812