vlatkovski

Sumx [jboi 2008]

Jun 29th, 2017
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. //it's not meant to be the best and most efficient code
  2. //i realised i could just divide sz by 2 to get the number needed, so i abandoned the code, which was unfinished, and submitted ASAP. it worked
  3. #include <iostream>
  4. #include <set>
  5. #include <map>
  6. using namespace std;
  7.  
  8. class Solution {
  9. private:
  10.     int N;
  11.     int X;
  12.     set<int> s;
  13.     int sz = 0;
  14.     map<int, set<int>> m;
  15. public:
  16.     Solution() {
  17.         cin >> N;
  18.         for (int i = 0; i < N; ++i) {
  19.             int a; cin >> a;
  20.             s.insert(a);
  21.         }
  22.         cin >> X;
  23.  
  24.         for (set<int>::iterator it = s.begin(); it != s.end(); ++it) {
  25.             int a = *it; //prviot broj
  26.             int b = X - a; //drugiot broj
  27.             if (s.find(b) != s.end()) {
  28.                 if (a > b) { int t = b; a = b; b = t; } //a<b sekogas
  29.                 if (m[a].find(b) == m[a].end()) { //parov ne e seuste najden
  30.                     m[a].insert(b);
  31.                     sz++;
  32.                 }
  33.             }
  34.         }
  35.  
  36.         sz /= 2; //better than fixing the above code, right? :^)
  37.         cout << sz;
  38.     }
  39. };
  40.  
  41. int main() {
  42.     Solution s;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment