Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //it's not meant to be the best and most efficient code
- //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
- #include <iostream>
- #include <set>
- #include <map>
- using namespace std;
- class Solution {
- private:
- int N;
- int X;
- set<int> s;
- int sz = 0;
- map<int, set<int>> m;
- public:
- Solution() {
- cin >> N;
- for (int i = 0; i < N; ++i) {
- int a; cin >> a;
- s.insert(a);
- }
- cin >> X;
- for (set<int>::iterator it = s.begin(); it != s.end(); ++it) {
- int a = *it; //prviot broj
- int b = X - a; //drugiot broj
- if (s.find(b) != s.end()) {
- if (a > b) { int t = b; a = b; b = t; } //a<b sekogas
- if (m[a].find(b) == m[a].end()) { //parov ne e seuste najden
- m[a].insert(b);
- sz++;
- }
- }
- }
- sz /= 2; //better than fixing the above code, right? :^)
- cout << sz;
- }
- };
- int main() {
- Solution s;
- }
Advertisement
Add Comment
Please, Sign In to add comment