卿學姐與魔法
Time Limit: 1200/800MS (Java/Others) ??? Memory Limit: 65535/65535KB (Java/Others)
“你的膜法也救不了你
在去拯救公主的道路上,卿學姐披荊斬棘,刀刃早已銹跡斑斑。
一日卿學姐正在為武器的問題發愁,碰到了正在賞樹的天行廖。
天行廖嘴角微揚,似乎看穿了卿學姐的心思,故意在此等待。
“少年,你渴望掌握雷電的力量嗎?”天行廖如是問道。
已經差不多是條咸魚的卿學姐欣然答應了。于是卿學姐開始跟隨魔法大師天行廖學習魔法的力量。
剛入門的卿學姐發現,每個魔法都是由兩種基本元素構成的,A元素和B元素。
而每個魔法的魔力是合成這個魔法的A元素和B元素的大小的和。
例如一個大小為3的A元素和一個大小為6的B元素,能構成一個魔力為9的魔法。
現在卿學姐收集了NN個A元素和NN個B元素。
敏銳的卿學姐立刻發現他能組合出N?NN?N種魔法。
謙虛的卿學姐并不希望自己太跳,所以他準備將這N?NN?N種魔法中的最小的NN種展示給天行廖檢查。
現在卿學姐想知道,這N?NN?N種魔法中最小的NN種是什么。
當然,得從小到大輸出哦~
Input
第一行一個整數NN
接下來一行有NN個數,表示NN個A元素
接下來一行有NN個數,表示NN個B元素
1≤N≤1000001≤N≤100000
1≤A[i],B[i]≤10000000001≤A[i],B[i]≤1000000000
Output
輸出NN行,每行一個整數
代表N?NN?N種魔法中最小的NN個
Sample input and output
Sample Input | Sample Output |
---|---|
5 1 3 2 4 5 6 3 4 1 7 | 2 3 4 4 5 |
#pragma GCC diagnostic error "-std=c++11" #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<vector> #include<queue>using namespace std; const int N = 100000 + 5; int A[N], B[N]; struct node{int a, b;bool operator < (const node & x)const{return A[a] + B[b] > A[x.a] + B[x.b];} };priority_queue<node> Q;void Work(int n){for(int i = 0; i < n; i++) Q.push((node){i, 0});for(int i = 0; i < n; i++){node tmp = Q.top(); Q.pop();printf("%d\n", A[tmp.a] + B[tmp.b]);tmp.b++;if(tmp.b == n) continue;Q.push( tmp );} } int main(){int n;scanf("%d", &n);for(int i = 0; i < n; i++) scanf("%d", &A[i]);for(int i = 0; i < n; i++) scanf("%d", &B[i]);sort(A, A + n);sort(B, B + n);Work( n );return 0; }
?