Advertisement
ivangarvanliev

Untitled

Sep 27th, 2024
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     int N;
  9.     cin >> N;
  10.     vector<int> kravi;
  11.  for (int i = 0; i < N; i++) {
  12.         int cnt, mleko;
  13.         cin >> cnt >> mleko;
  14.        
  15.         for (int j = 0; j < cnt; j++) {
  16.             kravi.push_back(mleko);
  17.         }
  18.     }
  19.     sort(kravi.begin(), kravi.end());
  20.     int vkkravi = kravi.size();
  21.     int rez = 0;
  22.  
  23.     for (int i = 0; i < vkkravi / 2; i++) {
  24.         int sega = kravi[i] + kravi[vkkravi - 1 - i];
  25.         rez = max(rez, sega);
  26.     }
  27.  
  28.     cout << rez << endl;
  29.  
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement