CSES Solutions
#1640Sorting and Searching

Sum of Two Values

View on CSES

Solution

1640-Sum_of_Two_Values.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n,x; cin>>n>>x;
7  map<int,int>mp;
8  int a=0,b=0;
9  for(int i=1;i<=n;++i){
10    int e; cin>>e;
11    if(mp[x-e]) a=i,b=mp[x-e];
12    mp[e]=i;
13  }
14  if(a+b) cout<<a<<" "<<b<<'\n';
15  else cout<<"IMPOSSIBLE\n";
16  return 0;
17}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.