File tree Expand file tree Collapse file tree 2 files changed +84
-0
lines changed
CSES/Sorting_and_Searching Expand file tree Collapse file tree 2 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ #include < bits/stdc++.h>
6+ using namespace std ;
7+ typedef long long ll;
8+
9+
10+ int solve (){
11+ int n,x,temp;
12+ cin>>n>>x;
13+ vector<pair<int ,int >> v (n);
14+ for (int i=0 ;i<n;i++){
15+ cin>>temp;
16+ // storing 0 based index
17+ v[i]={temp,i};
18+ }
19+ sort (v.begin (),v.end ());
20+ for (int i=0 ;i<n-2 ;i++){
21+ int req_sum=x-v[i].first ;
22+ int start = i+1 , end = n - 1 ;
23+ while (end > start)
24+ {
25+ temp = v[start].first + v[end].first ;
26+ if (temp == req_sum)
27+ {
28+ cout << v[i].second +1 <<" " << v[start].second + 1 << " " << v[end].second + 1 << endl;
29+ return 0 ;
30+ }
31+ if (temp < req_sum)
32+ start++;
33+ else
34+ end--;
35+ }
36+ }
37+ cout << " IMPOSSIBLE" << endl;
38+ return 0 ;
39+ }
40+ int main ()
41+ {
42+ int testCase=1 ;
43+ // cin>>testCase;
44+ while (testCase--){
45+ solve ();
46+ }
47+ return 0 ;
48+ }
Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ typedef long long ll;
6+ const ll INF = 1e18 ;
7+ const ll mod1 = 1e9 + 7 ;
8+ const ll mod2 = 998244353 ;
9+ // Add main code here
10+
11+ class Solution
12+ {
13+ public:
14+ int minimumLength (string str)
15+ {
16+ int s = 0 , e = str.size () - 1 ;
17+ while (s < e)
18+ {
19+ if (str[s] == str[e])
20+ {
21+ while (str[s] == str[s + 1 ] && s < e)
22+ s++;
23+ while (str[e] == str[e - 1 ] && s < e)
24+ e--;
25+ s++;
26+ e--;
27+ }
28+ else
29+ break ;
30+ }
31+ int ans = e - s + 1 ;
32+ if (ans < 0 )
33+ return 0 ;
34+ return ans;
35+ }
36+ };
You can’t perform that action at this time.
0 commit comments