///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define pi M_PI
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
//#define int long long
const int maxN = 1e6 + 9 ;
const int modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
void minimize(int &u, int v){
if(v < u) u = v;
}
void maximize(int &u, int v){
if(v > u) u = v;
}
int n, k, t, m, res;
vector<vector<int>> a, b;
pii A[maxN];
int l, r, lst[maxN], d[maxN];
bool vis[maxN];
vector<int> upd[maxN];
vector<pii> val[maxN];
long long sum[maxN];
void sub1(){
a = vector<vector<int>> (n + 5, vector<int>(m + 5) );
b= vector<vector<int>> (n + 5, vector<int>(m + 5) );
for(int i= 1;i <= n ;i++){
for(int j= 1;j <= m ;j++)cin >> a[i][j];
}
for(int i =1;i <= n ;i++){
for(int j = 1;j <=m ;j++)cin >> b[i][j];
}
int res = 1;
for(int j= 1;j <= m ;j++){
if(a[1][j] != 0)res =0;
}
cout << res;
}
void sub2(){
a = vector<vector<int>> (n + 5, vector<int>(m + 5) );
b= vector<vector<int>> (n + 5, vector<int>(m + 5) );
for(int i= 1;i <= n ;i++){
for(int j= 1;j <= m ;j++)cin >> a[i][j];
}
for(int i =1;i <= n ;i++){
for(int j = 1;j <=m ;j++)cin >> b[i][j];
}
while(res <= n){
int flag =0;
for(int i =1 ;i <= n ;i++){
if(vis[i])continue;
int ok =1;
for(int j=1 ; j <=m ;j++){
if(a[i][j] > sum[j]){
ok= 0;
break;
}
}
if(!ok)continue;
for(int j=1;j <= m ;j++){
sum[j] += b[i][j];
}
flag =1;
vis[i] = 1;
res++;
}
if(flag ==0)break;
}
cout << res;
exit(0);
}
void sub4(){
for(int i =1;i <= n ; i++){
for(int j =1; j <= m ;j ++){
int x;cin >> x;
val[j].pb({x, i});
}
}
for(int i =1;i <= n ; i++){
for(int j =1; j <= m ;j ++){
int x;cin >> x;
upd[i].pb(x);
}
}
for(int i =1;i <= m ;i++)sort(ALL(val[i]));
while(res <= n){
vector<int> can;
for(int j = 1; j <= m ;j++){
while(lst[j] < n && val[j][lst[j]].F <= sum[j] ){
++d[val[j][lst[j]].S];
if(d[val[j][lst[j]].S] == m )can.pb(val[j][lst[j]].S );
// cout << val[j][lst[j]].S << " ";
lst[j]++;
}
}
// cout << can.size();
if(can.empty())break;
res+= can.size();
for(auto x : can){
for(int j = 1; j <= m ;j++){
sum[j] += upd[x][j-1];
}
}
}
cout << res;
}
void sub3(){
for(int i =1;i <= n ;i++)cin >> A[i].F;
for(int i =1;i <= n ;i++)cin >> A[i].S;
sort(A +1, A +1 + n);
long long cur =0;
for(int i=1; i <= n ;i++){
if(cur >= A[i].F){
cur+= A[i].S;
res++;
}else break;
}
cout << res;
}
void solve(){
cin >> n >> m;
if(n==1){
sub1();
return;
}
if(m==1){
sub3();
return;
}
// if(n* m <= 10000 ) sub2();
sub4();
}
signed main(){
// freopen("name.inp","r",stdin);
// freopen("name.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
inp("task.inp");
t = 1;
// cin >> t;
while( t-- )solve();
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:13:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:158:5: note: in expansion of macro 'inp'
158 | inp("task.inp");
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
49488 KB |
Output is correct |
2 |
Correct |
10 ms |
49488 KB |
Output is correct |
3 |
Correct |
11 ms |
50168 KB |
Output is correct |
4 |
Correct |
130 ms |
100356 KB |
Output is correct |
5 |
Correct |
146 ms |
100496 KB |
Output is correct |
6 |
Correct |
130 ms |
100364 KB |
Output is correct |
7 |
Correct |
101 ms |
100364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
51536 KB |
Output is correct |
2 |
Correct |
9 ms |
51536 KB |
Output is correct |
3 |
Correct |
9 ms |
51536 KB |
Output is correct |
4 |
Correct |
9 ms |
49488 KB |
Output is correct |
5 |
Correct |
8 ms |
49632 KB |
Output is correct |
6 |
Correct |
8 ms |
51536 KB |
Output is correct |
7 |
Correct |
12 ms |
51940 KB |
Output is correct |
8 |
Correct |
11 ms |
51792 KB |
Output is correct |
9 |
Correct |
12 ms |
51792 KB |
Output is correct |
10 |
Correct |
12 ms |
51716 KB |
Output is correct |
11 |
Correct |
11 ms |
51928 KB |
Output is correct |
12 |
Correct |
11 ms |
51960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
49488 KB |
Output is correct |
2 |
Correct |
8 ms |
51536 KB |
Output is correct |
3 |
Correct |
11 ms |
51536 KB |
Output is correct |
4 |
Correct |
27 ms |
53828 KB |
Output is correct |
5 |
Correct |
27 ms |
53600 KB |
Output is correct |
6 |
Correct |
204 ms |
59188 KB |
Output is correct |
7 |
Correct |
185 ms |
59404 KB |
Output is correct |
8 |
Correct |
197 ms |
59192 KB |
Output is correct |
9 |
Correct |
184 ms |
59208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
49488 KB |
Output is correct |
2 |
Correct |
10 ms |
49488 KB |
Output is correct |
3 |
Correct |
11 ms |
50168 KB |
Output is correct |
4 |
Correct |
130 ms |
100356 KB |
Output is correct |
5 |
Correct |
146 ms |
100496 KB |
Output is correct |
6 |
Correct |
130 ms |
100364 KB |
Output is correct |
7 |
Correct |
101 ms |
100364 KB |
Output is correct |
8 |
Correct |
9 ms |
51536 KB |
Output is correct |
9 |
Correct |
9 ms |
51536 KB |
Output is correct |
10 |
Correct |
9 ms |
51536 KB |
Output is correct |
11 |
Correct |
9 ms |
49488 KB |
Output is correct |
12 |
Correct |
8 ms |
49632 KB |
Output is correct |
13 |
Correct |
8 ms |
51536 KB |
Output is correct |
14 |
Correct |
12 ms |
51940 KB |
Output is correct |
15 |
Correct |
11 ms |
51792 KB |
Output is correct |
16 |
Correct |
12 ms |
51792 KB |
Output is correct |
17 |
Correct |
12 ms |
51716 KB |
Output is correct |
18 |
Correct |
11 ms |
51928 KB |
Output is correct |
19 |
Correct |
11 ms |
51960 KB |
Output is correct |
20 |
Correct |
10 ms |
49488 KB |
Output is correct |
21 |
Correct |
8 ms |
51536 KB |
Output is correct |
22 |
Correct |
11 ms |
51536 KB |
Output is correct |
23 |
Correct |
27 ms |
53828 KB |
Output is correct |
24 |
Correct |
27 ms |
53600 KB |
Output is correct |
25 |
Correct |
204 ms |
59188 KB |
Output is correct |
26 |
Correct |
185 ms |
59404 KB |
Output is correct |
27 |
Correct |
197 ms |
59192 KB |
Output is correct |
28 |
Correct |
184 ms |
59208 KB |
Output is correct |
29 |
Correct |
191 ms |
66536 KB |
Output is correct |
30 |
Correct |
197 ms |
63816 KB |
Output is correct |
31 |
Correct |
243 ms |
67296 KB |
Output is correct |
32 |
Correct |
160 ms |
66376 KB |
Output is correct |
33 |
Correct |
165 ms |
63816 KB |
Output is correct |
34 |
Correct |
198 ms |
67132 KB |
Output is correct |
35 |
Correct |
243 ms |
67308 KB |
Output is correct |
36 |
Correct |
189 ms |
67144 KB |
Output is correct |
37 |
Correct |
222 ms |
67144 KB |
Output is correct |
38 |
Correct |
149 ms |
67556 KB |
Output is correct |