#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<cassert>
#include<unordered_map>
#include <queue>
#include <cstdint>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
#define int long long
using namespace std;
const int mod=998244353,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30;
//#undef int
int n,k,m,q;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int32_t main(){
fastio
cin>>n>>k;
vector<vector<int>>req(n,vector<int>(k));
vector<vector<int>>add(n,vector<int>(k));
for(int i=0;i<n;i++)for(int j=0;j<k;j++)cin>>req[i][j];
for(int i=0;i<n;i++)for(int j=0;j<k;j++)cin>>add[i][j];
vector<vector<pii>>ord(k);
vector<int>cur(k,0),point(k,0),cnt(n,0);
for(int j=0;j<k;j++){
for(int i=0;i<n;i++)ord[j].pb({req[i][j],i});
sort(all(ord[j]));
}
vector<int>can,used(n,0);
int ans=0,loop=0;
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
while(point[j]<n&&cur[j]>=ord[j][point[j]].f){
loop++;
cnt[ord[j][point[j]].s]++;
if(cnt[ord[j][point[j]].s]==k)can.pb(ord[j][point[j]].s);
point[j]++;
}
}
while(!can.empty()){
ans++;
for(int j=0;j<k;j++)cur[j]+=add[can.back()][j];
can.pop_back();
}
}
cout<<ans;
}
Compilation message
Main.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize ("03,unroll-lopps")
| ^
Main.cpp:38:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
38 | void setIO(string name){
| ^
Main.cpp:43:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
43 | int32_t main(){
| ^
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
1360 KB |
Output is correct |
4 |
Correct |
190 ms |
95668 KB |
Output is correct |
5 |
Correct |
167 ms |
95676 KB |
Output is correct |
6 |
Correct |
173 ms |
95676 KB |
Output is correct |
7 |
Correct |
142 ms |
92276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
848 KB |
Output is correct |
8 |
Correct |
3 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
3 ms |
848 KB |
Output is correct |
11 |
Correct |
3 ms |
848 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
4 ms |
1872 KB |
Output is correct |
4 |
Correct |
39 ms |
16828 KB |
Output is correct |
5 |
Correct |
33 ms |
16060 KB |
Output is correct |
6 |
Correct |
360 ms |
149136 KB |
Output is correct |
7 |
Correct |
400 ms |
152744 KB |
Output is correct |
8 |
Correct |
385 ms |
160280 KB |
Output is correct |
9 |
Correct |
406 ms |
152484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
1360 KB |
Output is correct |
4 |
Correct |
190 ms |
95668 KB |
Output is correct |
5 |
Correct |
167 ms |
95676 KB |
Output is correct |
6 |
Correct |
173 ms |
95676 KB |
Output is correct |
7 |
Correct |
142 ms |
92276 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
848 KB |
Output is correct |
15 |
Correct |
3 ms |
848 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
3 ms |
848 KB |
Output is correct |
18 |
Correct |
3 ms |
848 KB |
Output is correct |
19 |
Correct |
3 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
4 ms |
1872 KB |
Output is correct |
23 |
Correct |
39 ms |
16828 KB |
Output is correct |
24 |
Correct |
33 ms |
16060 KB |
Output is correct |
25 |
Correct |
360 ms |
149136 KB |
Output is correct |
26 |
Correct |
400 ms |
152744 KB |
Output is correct |
27 |
Correct |
385 ms |
160280 KB |
Output is correct |
28 |
Correct |
406 ms |
152484 KB |
Output is correct |
29 |
Correct |
241 ms |
50400 KB |
Output is correct |
30 |
Correct |
222 ms |
45452 KB |
Output is correct |
31 |
Correct |
280 ms |
59052 KB |
Output is correct |
32 |
Correct |
178 ms |
45384 KB |
Output is correct |
33 |
Correct |
190 ms |
42056 KB |
Output is correct |
34 |
Correct |
238 ms |
42948 KB |
Output is correct |
35 |
Correct |
262 ms |
58788 KB |
Output is correct |
36 |
Correct |
228 ms |
46024 KB |
Output is correct |
37 |
Correct |
251 ms |
48868 KB |
Output is correct |
38 |
Correct |
171 ms |
51120 KB |
Output is correct |