Advertisement
Guest User

123142

a guest
Oct 13th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. ios::sync_with_stdio(0);
  6. int t, n, k, f[3030], s[3030];
  7. long long int sum=0, cn=0, tem;
  8. cin >> t;
  9. for(int i=0;i<t;i++)
  10. {
  11. cin >> n >> k;
  12. for(int q=0;q<n;q++)
  13. {
  14. for(int y=0;y<3;y++)
  15. {
  16. cin >> f[y];
  17. }
  18. for(int j=0;j<3;j++)
  19. {
  20. for(int r=0;r<2;r++)
  21. {
  22. if(f[r]>f[r+1])
  23. {
  24. tem = f[r+1];
  25. f[r+1] = f[r];
  26. f[r] = tem;
  27. }
  28. }
  29. }
  30. s[cn] = f[0];
  31. cn++;
  32. s[cn] = f[1];
  33. cn++;
  34. }
  35. for(int j=0;j<2*n;j++)
  36. {
  37. for(int r=0;r<(2*n)-1;r++)
  38. {
  39. if(s[r]>s[r+1])
  40. {
  41. tem = s[r+1];
  42. s[r+1] = s[r];
  43. s[r] = tem;
  44. }
  45. }
  46. }
  47. for(int y=0;y<k;y++)
  48. {
  49. sum+=s[y];
  50. }
  51. cout << sum << endl;
  52. sum = 0;
  53. cn = 0;
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement