#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include<vector>
int main() {
// your code goes here
vector<int>arr1={1,4,5,7};
vector<int>arr2={10,20,30,40};
int x=32;
int a,b;
int closest_sum=INT_MAX;
long long answer=-10000000000000;
for(int i=0;i<arr1.size();i++)
{
int sum=0;
for(int j=0;j<arr2.size();j++)
{
sum=arr1[i]+arr2[j];
if(sum<=x)
{
// int y = abs(x-sum);
// //closest_sum=min(y,closest_sum);
// if(closest_sum>y)
// {
// closest_sum=y;
// a=arr1[i];
// b=arr2[j];
// }
if(answer<sum)
{
answer=sum;
a=arr1[i];
b=arr2[j];
}
}
}
}
cout<<a<<" "<<b;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8dmVjdG9yPgppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCQoJdmVjdG9yPGludD5hcnIxPXsxLDQsNSw3fTsKCXZlY3RvcjxpbnQ+YXJyMj17MTAsMjAsMzAsNDB9OwoJaW50IHg9MzI7CglpbnQgYSxiOwoJaW50IGNsb3Nlc3Rfc3VtPUlOVF9NQVg7Cglsb25nIGxvbmcgYW5zd2VyPS0xMDAwMDAwMDAwMDAwMDsKCWZvcihpbnQgaT0wO2k8YXJyMS5zaXplKCk7aSsrKQoJIHsKCSAJaW50IHN1bT0wOwoJIAlmb3IoaW50IGo9MDtqPGFycjIuc2l6ZSgpO2orKykKCSAJIHsKCSAJIAlzdW09YXJyMVtpXSthcnIyW2pdOwoJIAkgCWlmKHN1bTw9eCkKCSAJIAkgewoJIAkgCSAJLy8gaW50ICB5ID0gYWJzKHgtc3VtKTsKCSAJIAkgCS8vIC8vY2xvc2VzdF9zdW09bWluKHksY2xvc2VzdF9zdW0pOwoJIAkgCSAJLy8gaWYoY2xvc2VzdF9zdW0+eSkKCSAJIAkgCS8vICB7CgkgCSAJI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