2019-04-07 05:21:42 C

C

Copy Copied! Full
#include <stdio.h> #include <stdlib.h> int compare_longlong(const void *a, const void *b) { return *(long long*)b - *(long long*)a; } long long AB[1000000]={}; long long ABC[3000000]={}; int main(void){ long X,Y,Z,K; long long A[1000]={},B[1000]={},C[1000]={}; long i,j; scanf("%d %d %d %d",&X,&Y,&Z,&K); for(i=0;i<X;i++){ scanf("%lld",&A[i]); } for(i=0;i<Y;i++){ scanf("%lld",&B[i]); } for(i=0;i<Z;i++){ scanf("%lld",&C[i]); } qsort(A,X,sizeof(long long),compare_longlong); qsort(B,Y,sizeof(long long),compare_longlong); qsort(C,Z,sizeof(long long),compare_longlong); int temp=0; for(i=0;i<X;i++){ for(j=0;j<Y;j++){ AB[temp]=A[i]+B[j]; temp++; } } qsort(AB,temp,sizeof(long long),compare_longlong); int temp2 = 0; for(i=0;i<3000;i++){ for(j=0;j<Z;j++){ ABC[temp2]= AB[i] + C[j]; temp2 ++; } } qsort(ABC,temp2,sizeof(long long),compare_longlong); for(i=0;i<K;i++){ printf("%lld\n",ABC[i]); } return 0; }