# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1269889 | tungtungsahur | Topical (NOI23_topical) | C++17 | 291 ms | 78572 KiB |
#include<bits/stdc++.h>
#define ll long long
#define dn cout << "\n";
#define bit(i, j) ((i >> j) & 1)
#define F first
#define S second
#define name "task"
#define con(x) __buildtin_popcount(x)
#define sz(x) (int)(x.size())
#define pb push_back
using namespace std;
const int M = 1e6 + 2;
const int N = 250002;
const int BL = 320;
const ll MOD = 1e9 + 7;
const ll oo = 2e15;
int n, k, rs = 0;
void solve(){
cin >> n >> k;
vector<ll> pos(k + 1, -1), st(n + 1, 0), cur;
vector<vector<int>> p(n + 1, vector<int> (k + 1));
vector<bool> used(n + 1, 0);
vector<vector<pair<int,int>>> vec(k + 1);
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= k; j ++){
if(i == 1) cur.pb(0);
int x; cin >> x;
vec[j].pb({x, i});
}
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= k; j ++)
cin >> p[i][j];
}
for(int j = 1; j <= k; j ++){
sort(vec[j].begin(), vec[j].end());
}
while(1){
bool appear = 0;
for(int j = 1; j <= k; j ++){
while(pos[j] + 1 < n && cur[j - 1] >= vec[j][pos[j]+1].F){
st[vec[j][pos[j]+1].S] ++;
if(st[vec[j][pos[j]+1].S] == k){
rs ++; appear = 1;
for(int i = 1; i <= k; i ++) cur[i - 1] += p[vec[j][pos[j]+1].S][i];
}
pos[j] ++;
}
}
if(appear == 0) break;
}
cout << rs;
}
main(){
cin.tie(0) -> ios::sync_with_stdio(0);
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
solve();
}
/*
Test :
4 3
5 1 0
0 1 5
0 0 0
7 7 7
0 5 6
1 1 1
8 2 0
8 1 4
Output :
4
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |