Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int tab[20],stala=300,wynik,wynik2,pom,od;
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0);
  11. cout.tie(0);
  12.  
  13.  
  14. int t,n;
  15. cin>>t;
  16. for(int i=1;i<=t;i++)
  17. {
  18. cin>>n;
  19. for(int j=1;j<=n;j++)
  20. {
  21. cin>>tab[i];
  22. }
  23. sort(tab+1,tab+n+1);
  24. for(int j=1;j<=n;j++)
  25. {
  26. if(tab[j]!=0)
  27. {
  28. od=j;
  29. break;
  30. }
  31. }
  32. for(int j=1;j<=n;j++)
  33. {
  34. if(stala-tab[j]>=0)stala-=tab[j];
  35.  
  36. else
  37. {
  38. wynik=j-1;
  39. break;
  40. }
  41. cout<<stala<<"\n";
  42. }
  43. for(int j=1;j<=wynik;j--)
  44. {
  45. pom=wynik;
  46. wynik2+=tab[j]*pom;
  47. pom--;
  48. }
  49. cout<<wynik<<" "<<wynik2<<"\n";
  50. stala=300;
  51. }
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement