fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int t=0; //ilosc testów
  8. int N=0; //ilosc pomiarow
  9.  
  10. cin>>t;
  11. for (int j=0; j<t; j++)
  12. {
  13. //bool pom;
  14. int *tab;
  15. int min;
  16. int max=0;
  17. cin>>N;
  18. tab= new int[N];
  19. for(int k=0;k<N;k++) //zwroci max przy okazji
  20. {cin>>tab[k]; max+=tab[k];}
  21. sort(tab, tab+N, greater < int >());
  22. tab[0]*=-1;
  23. min=tab[0]; //zawiera kolejne wart_predk
  24. for(int i=0;i<N-1;i++) //szuka minimum
  25. {
  26. if(abs(min-tab[i+1]) >= abs(min+tab[i+1]))
  27. tab[i+1]*=1;
  28. else tab[i+1]*=-1;
  29. min+=tab[i+1]; //policz akt predkosc
  30. }
  31. cout<<abs(min)<<" "<<max<<endl; //moze jechac na wstecznym(180,20,60=>-100)
  32. delete [] tab;
  33. }
  34. //system("pause");
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5380KB
stdin
1
5
17
15
6
18
10
stdout
2 66