#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int N, K, C;
deque<vector<int> > vt;
int sidx;
bool sf(vector<int> a, vector<int> b){
return a[sidx]>b[sidx];
}
priority_queue<int, vector<int>, greater<int> > pq;
void sortvt(int x){
sidx = x;
sort(vt.begin(), vt.end(), sf);
}
vector<vector<int> > st;
bool calc(int x){
vector<vector<int> > vt2;
if(x==K){
int sum = 0;
int pl = 0;
for(int i=0; i<K; i++){
pl = 0;
for(int j=0; j<K; j++){
pl = max(pl, st[j][i]);
//cout<<st[i][j]<<" ";
}//cout<<endl;
sum+=pl;
}
if(pq.size()==C){
if(sum<pq.top()){
return false;
}
pq.pop(); pq.push(sum);
}
else pq.push(sum);
//cout<<sum<<endl;
return true;
}
sortvt(x);
while(!vt.empty()){
st.push_back(vt.front());
vt2.push_back(vt.front());
vt.pop_front();
if(!calc(x+1)){
while(!vt2.empty()){
vt.push_front(vt2.back()); vt2.pop_back();
}
return false;
}
st.pop_back();
}
while(!vt2.empty()){
vt.push_front(vt2.back()); vt2.pop_back();
}
return true;
}
int main(){
scanf("%d%d%d", &N, &K, &C);
for(int i=0; i<N; i++){
vector<int> v(K);
for(int j=0; j<K; j++){
int x; scanf("%d", &x);
v[j] = x;
}
vt.pb(v);
}
calc(0);
printf("%d", pq.top());
return 0;
}
Compilation message
olympiads.cpp: In function 'bool calc(int)':
olympiads.cpp:54:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pq.size()==C){
~~~~~~~~~^~~
olympiads.cpp: In function 'int main()':
olympiads.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &N, &K, &C);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
olympiads.cpp:88:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x; scanf("%d", &x);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |