第一行是表達輸入幾行每行有幾個數字,
那你可以利用for迴圈創造出n行樣大小的陣列,
之後排列將最大值相加,
後除以那些最大值若可以除盡的話就將數字印出來。
#include<bits/stdc++.h>
using namespace std;
int a,b;
std::queue<int>q ;
std::queue<int>k ;
signed main(){
cin>>a>>b;
int arr[b];
int ans[a]={};
int c=0;
for(int i=1;i<=a;i++){
arr[b]={};
for(int j=0;j<b;j++){
cin>>arr[j];
} sort(arr, arr+b);
c=c+arr[b - 1];
k.push(arr[b- 1]);
}
while(!k.empty()){
if(c%k.front()==0){
q.push(k.front());
k.pop();
}else{
k.pop();
}
}
if(q.size()>0){
cout<<c<<"\n";
while (!q.empty()) {
if(q.size()==1){
cout<<q.front();
q.pop();
}else{
cout<<q.front()<<" ";
q.pop();
}
}
}else{
cout<<c<<"\n"<<"-1";
}
}