-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.cpp
More file actions
47 lines (46 loc) · 939 Bytes
/
Copy pathtempCodeRunnerFile.cpp
File metadata and controls
47 lines (46 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n, m, tmp, msum = 0;
vector<int> a;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
vector<int> v;
for (int j = 0; j < m; j++)
{
cin >> tmp;
v.push_back(tmp);
}
sort(v.begin(), v.end());
msum += v[(int)v.size() - 1];
a.push_back(v[(int)v.size() - 1]);
}
cout << msum << endl;
reverse(a.begin(), a.end());
for (int i = (int)a.size() - 1; i >= 0; i--)
{
if (msum % a[i] == 0)
{
if (i == (int)a.size() - 1 )
{
cout << a[i];
}else
{
cout << " " << a[i];
}
}
else
{
a.pop_back();
}
}
if (a.empty() == 1)
{
cout << -1;
}
return 0;
}