#38305: c++


weiyoung0912@gmail.com (Yannick)

學校 : 不指定學校
編號 : 251771
來源 : [150.116.42.118]
最後登入時間 :
2024-04-27 22:10:35
c295. APCS-2016-1029-2最大和 -- 2016年10月APCS | From: [150.116.42.118] | 發表日期 : 2023-11-11 17:06

include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    int a,b,c,bigbig,s=0;
    vector<int> big,m;
    cin>>a>>b;
    bool tof=false;
    for(int i=0;i<a;i++){
        bigbig=0;
        for(int k=0;k<b;k++){
            cin>>c;
            if(bigbig<c){
                bigbig=c;
            }
        }
        big.push_back(bigbig);
    }
    for(int r=0;r<big.size();r++){
        s+=big[r];
    }
    cout<<s<<"\n";
    for(int y=0;y<a;y++){
        if((s%big[y])==0){
            tof=true;
            m.push_back(big[y]);
        }
    }
    size_t sz=m.size();
    if(tof==false){
        cout<<-1;
    }
    else{
        for(int z=0;z<sz;z++){
            if(z+1==sz){
                cout<<m[z];
            }
            else{
                cout<<m[z]<<" ";
            }
        }
    }
    cout<<"\n";
    return 0;
}

use 2ms

 
ZeroJudge Forum