#include <stdio.h> int ability[50][2]={0}; int answer[10000]={0}; void line(int n); //내림차순 정렬 int cal(int n); int main(void) { int t, n, i, j; scanf(" %d", &t); for(i=0; i<t; i++) { scanf(" %d", &n); for(j=0; j<n; j++) //KAIST { scanf(" %d", &ability[j][0]); } for(j=0; j<n; j++) //Postech { scanf(" %d", &ability[j][1]); } line(n); answer[i]=cal(n); } for(i=0; i<t; i++) printf("%d\n", answer[i]); return 0; } void line(int n) { int i, j, max=0, temp; for(i=0; i<(n-1); i++) { max=i; for(j=i+1; j<n; j++) { if(ability[max][0]<ability[j][0]) max=j; } if(max!=i) { temp=ability[i][0]; ability[i][0]=ability[max][0]; ability[max][0]=temp; } } for(i=0; i<(n-1); i++) { max=i; for(j=i+1; j<n; j++) { if(ability[max][1]<ability[j][1]) max=j; } if(max!=i) { temp=ability[i][1]; ability[i][1]=ability[max][1]; ability[max][1]=temp; } } } int cal(int n) { int k=0, p=0, sum=0; while(k<n && p<n) { if(ability[k][0]>ability[p][1]) { sum+=ability[k][0]; k++; p++; } else p++; } return sum; }
2018.06.09 11:18
정올 - 실전대비 - Duel(1312)
조회 수 64 추천 수 0 댓글 0