#include<iostream> 02.#include<algorithm> 03.using namespace std; 04. 05.bool cmp(int a,int b){ 06. return a>b; 07.} 08. 09.int p[9000010],n,k; 10.int a[3005]; 11. 12.int main(){ 13. while(cin>>n>>k){ 14. for( int i = 0 ; i < n ; ++i ) 15. cin>>a[i]; 16. int l=0; 17. for( int i = 0 ; i < n ; ++i ) 18. for( int j = 0 ; j < n ; ++j ) 19. if( i != j && j > i ) 20. p[l++] = a[i] + a[j]; 21. sort(p,p+l,cmp); 22. cout<<p[0]; 23. for( int i = 1 ; i < k ; ++i ) 24. cout<<‘ ‘<<p[i]; 25. cout<<endl; 26. } 27. return 0; 28.}
时间: 2024-12-08 03:10:15