#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define nn '\n'
const int N = 2e5 + 1;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
if (n == 1) {
int r[n + 1][k + 1], u[n + 1][k + 1];
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= k; j++)
{
cin >> r[i][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= k; j++)
{
cin >> u[i][j];
}
}
int cnt = 0;
int mus = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= k; j++)
{
if (mus >= r[i][j])
{
mus += u[i][j];
cnt++;
}
}
}
if (cnt == k)
{
cout << 1 << nn;
}
else
{
cout << 0 << nn;
}
}
else
{
vector<int> a(n + 1) , b(n + 1);
vector<pair<int , int>> p(n * 2 + 2);
for(int i = 1; i <= n ; i++)
{
cin >> a[i];
}
for(int i = 1; i <= n ; i++)
{
cin >> b[i];
}
for(int i = 1; i <= n ; i++)
{
p.pb({a[i] , b[i]});
}
int cnt = 0 , sum = 0;
sort(p.begin() + 1 , p.end());
for(int i = 1; i <= n ; i++)
{
if(sum >= p[i].first)
{
sum +=p[i].second;
cnt++;
}
}
cout << cnt << nn ;
}
}
| # | 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... |