-
Notifications
You must be signed in to change notification settings - Fork 0
/
Market_Survey.cpp
106 lines (70 loc) · 1.54 KB
/
Market_Survey.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int , int>
#define vi vector<int>
#define ll long long
#define INF 1000000005
#define endl '\n'
int main()
{
fast_io;
int n,m;
cin>>n>>m;
int def[n];
forn(i, n) cin>>def[i];
int count[4][n];
memset(count, 0, sizeof(count));
forn(i, n) {
int c = def[i];
// Set count
count[c-1][i] = 1;
}
int mat[m][n];
forn(i, m) {
forn(j, n) cin>>mat[i][j];
}
// Logic
forn(i, m) {
int sc=0;
forn(j, n) {
int ans = mat[i][j];
count[ans-1][j]++;
if(mat[i][j]==def[j]) sc++;
}
cout<<sc<<endl;
for(int j=0; j<n; j++) {
int mx=0, ans=0;
for(int k=0; k<4; k++) {
if(mx < count[k][j]) {
mx = count[k][j];
ans = k+1;
}
}
def[j] = ans;
}
}
cout<<"final key: ";
forn(i, n) cout<<def[i]<<" ";
cout<<endl;
// according to latest key
int mx=0, id=0;
forn(i, m) {
int sc=0;
forn(j, n){
if(mat[i][j]==def[j]) sc++;
}
if(mx < sc) {
id = i+1;
mx = sc;
}
}
cout<<id<<" "<<mx<<endl;
return 0;
}
// End