Untitled

mail@pastecode.io avatar
unknown
c_cpp
8 months ago
967 B
0
Indexable
Never
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int solve(vector<int>& lend, vector<int>& pay) {
    vector<pair<int,int>> data;
    for (int i = 0; i < lend.size(); i++) {
        data.push_back({pay[i], lend[i]});
    }
    sort(data.begin(), data.end());

    int days = 0;
    int curLoan = 0;
    for (int i = 0; i < data.size(); i++) {
        if (data[i].second < curLoan) {
            continue;
        }
        curLoan = data[i].first;
        days++;
    }
    return days;
}

int main() {
    vector<int> lend = {2, 1, 5};
    vector<int> payback = {2, 2, 5};
    vector<int> lend1 = {1, 1, 1, 2};
    vector<int> payback1 = {2, 2, 2, 3};
    vector<int> lend2 = {1, 1, 1, 2};
    vector<int> payback2 = {4, 2, 2, 3};

    cout << solve(lend, payback) << endl; // 3
    cout << solve(lend1, payback1) << endl; // 2
    cout << solve(lend2, payback2) << endl; // 2

    return 0;
}