标签:
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 7762 | Accepted: 2565 |
Description
Input
Output
Sample Input
1 2 3 1 2 3 2 2 3
Sample Output
3 3 4
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdlib> #include<queue> #include<vector> #include<stack> using namespace std; int tt,m,n; int a[2010],b[2010],heap[2010]; int main() { scanf("%d",&tt); while(tt--) { scanf("%d%d",&m,&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); m--; while(m--) { for(int i=0;i<n;i++) scanf("%d",&b[i]); sort(b,b+n); for(int i=0;i<n;i++) heap[i]=a[i]+b[0]; make_heap(heap,heap+n); for(int i=1;i<n;i++) { bool ok=0; for(int j=0;j<n;j++) { int temp=a[j]+b[i]; if(temp<heap[0]) { pop_heap(heap,heap+n); heap[n-1]=temp; push_heap(heap,heap+n); ok=1; } else break; } if(!ok) break; } for(int i=0;i<n;i++) a[i]=heap[i]; sort(a,a+n); } for(int i=0;i<n-1;i++) printf("%d ",a[i]); printf("%d\n",a[n-1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4388104.html