1245 min N sum, 1245 min
1245 minimum N sum
Time Limit: 1 s space limit: 128000 KB title level: Diamond Title Description
Description
There are two sequences A and B with the length of N. For each number of A and B, we can get N ^ 2 and calculate the N ^ 2 and the N smallest N.
Input description
Input Description
Enter a positive integer N in the first line; N integers Ai In the second line and Ai ≤ 10 ^ 9; N integers in the third line Bi,
And Bi ≤ 10 ^ 9
Output description
Output Description
The output contains only one row and n integers. The smallest sum of N is output from small to large.
Separated by spaces.
Sample Input
Sample Input
5
1 3 2 4 5
6 3 4 1 7
Sample output
Sample Output
2 3 4 4 5
Data range and prompt
Data Size & Hint
[Data scale] for 100% of data, 1 ≤ N ≤ 100000.
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 using namespace std; 6 int a[100001]; 7 int b[100001]; 8 priority_queue<int>ans; 9 int can[1001][1001];10 int c[100001];11 int main()12 {13 int n;14 scanf("%d",&n);15 for(int i=1;i<=n;i++)16 scanf("%d",&a[i]);17 for(int i=1;i<=n;i++)18 scanf("%d",&b[i]);19 sort(a+1,a+n+1);20 sort(b+1,b+n+1);21 int now=1;22 for(int i=1;i<=n;i++)23 {24 ans.push(a[1]+b[i]);25 }26 for(int i=2;i<=n;i++)27 {28 for(int j=1;j<=n;j++)29 {30 int sum=a[i]+b[j];31 if(sum>=ans.top())32 {33 break;34 }35 else36 {37 ans.pop();38 ans.push(sum);39 }40 }41 }42 //now=1;43 for(int i=1;i<=n;i++)44 {45 c[i]=ans.top();46 ans.pop();47 }48 for(int i=n;i>=1;i--)49 printf("%d ",c[i]);50 return 0;51 }
That is, no heap is used, and priority queue is usually used =. =