Advertisement
7oSkaaa

Sum of Three Values

Aug 11th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define cin(vec) for(auto& i : vec) cin >> i
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  8. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define fixed(n) cout << fixed << setprecision(n)
  11. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  12. #define fill(vec, value) memset(vec, value, sizeof(vec));
  13. #define Num_of_Digits(n) ((int)log10(n)+1)
  14. #define all(vec) vec.begin(),vec.end()
  15. #define rall(vec) vec.rbegin(),vec.rend()
  16. #define sz(x) int(x.size())
  17. #define fi first
  18. #define se second
  19. #define Pair pair < int, int >
  20. #define ll long long
  21. #define ull unsigned long long
  22. #define Mod  1'000'000'007
  23. #define INF 2'000'000'000
  24. #define PI acos(-1)
  25.  
  26. void Code_Crush(){
  27.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28.   #ifndef ONLINE_JUDGE
  29.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  30.   #endif
  31. }
  32.  
  33. int main(){
  34.   Code_Crush();
  35.   int n, target1;                            cin >> n >> target1;
  36.   vector < int > nums(n);
  37.   cin(nums);
  38.   vector < pair < int, int > > idx;
  39.   for(int i = 0; i < nums.size(); i++)
  40.       idx.push_back({nums[i], i});
  41.   sort(idx.begin(), idx.end());
  42.   for(int i = 0; i < n; i++){
  43.     int target = target1 - nums[i];
  44.     int l = 0, r = nums.size() - 1;
  45.     while(l < r){
  46.         if(i == idx[l].se) l++;
  47.         else if(i == idx[r].se) r--;
  48.         else {
  49.           if(idx[l].first + idx[r].first == target){
  50.            return cout << idx[l].second + 1 << " " << idx[r].second + 1 << " " << i + 1, 0;
  51.           }
  52.           (idx[l].first + idx[r].first > target ? r-- : l++);
  53.         }
  54.     }
  55.   }
  56.   cout << "IMPOSSIBLE";
  57.   Time
  58.   return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement