标签:
6 15 1 2 4 7 11 15
4 11
Code:
#include <cstdio> #include <algorithm> #define INF 0x7fffffffffffffff //考虑到long long 类型,8个字节 using namespace std; int arr[1000010]; int main() { int n,k,num1,num2; int *head,*tail; long long minVal; bool havaAnswer; while(scanf("%d%d",&n,&k)!=EOF){ for(int i=0;i<n;++i){ scanf("%d",&arr[i]); } head=arr; tail=arr+n-1; minVal=INF; havaAnswer=false; while(head<tail){ if(*head+*tail==k){ havaAnswer=true; if((long long)(*head)*(*tail)<minVal){ num1=*head; num2=*tail; minVal=(long long)(*head)*(*tail); } ++head; --tail; }else{ if(*head+*tail<k){ ++head; }else{ --tail; } } } if(havaAnswer){ int a=num1,b=num2; if(num1>num2){ a=num1; b=num2; } printf("%d %d\n",a,b); }else{ printf("%d %d\n",-1,-1); } } return 0; } /************************************************************** Problem: 1352 User: lcyvino Language: C++ Result: Accepted Time:1430 ms Memory:5424 kb ****************************************************************/
标签:
原文地址:http://www.cnblogs.com/Murcielago/p/4214536.html