#include <bits/stdc++.h>
using namespace std;
const int N = 1e6,INF = 0x3f3f3f3f;
int a[N];
int n,x;
void fun(int n)
{
int left = 0, right = n-1;
while(left < right)
{
int ans=a[left] + a[right];
if(ans == x)
{
cout<<a[left]<<' '<<a[right]<<endl;
left++, right--;
}
else if(ans < x)
{
left++;
}
else if(ans > x)
{
right--;
}
}
}
int main()
{
cin>>n>>x;
for(int i=0;i<n;i++) {
cin>>a[i];
}
fun(n);
}
/*
9 16
1 2 3 5 6 7 11 13 15
*/
原文地址:https://www.cnblogs.com/Roni-i/p/9253303.html
时间: 2024-10-10 01:13:28