Advertisement
rengetsu

VGTU_ACM_ICPC_D

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