反向扫描
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
using LL = long long;
const int N = 1e6 + 10;
int a[N];
int main(){
int n,m;
while(cin>>a[n],a[n]) n++;
cin>>m;
sort(a,a+n);
int i=0,j=n-1;
while(i<j){
int sum=a[i]+a[j];
if(sum>m) j--;
if(sum<m) i++;
if(sum==m){
cout<<a[i]<<' '<<a[j]<<'\n';
i++;
}
}
return 0;
}