Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 days ago
871 B
1
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

bool cmp(pair<int, int> a, pair<int, int> b)
{
    return a.first > b.first;
}

bool cmp2(pair<int, int> a, pair<int, int> b)
{
    return a.second < b.second;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int k, n;
    cin >> k >> n;
    vector<pair<int, int>> arr(k);
    vector<int> b(k - n + 1);

    for (int i = 0; i < k; i++)
    {
        cin >> arr[i].first >> arr[i].second;
    }

    sort(arr.begin(), arr.end(), cmp);

    for (int i = 0; i < n; i++)
    {
        priority_queue<int> pq;
        int x;
        pq.push( arr[i].second );
        pq.push( arr[i + 1].second );
        pq.push( arr[i + 2].second );
        b[i] = arr[i].first + pq.top();
    }

    cout << *min_element(b.begin(), b.end()) << "\n";
}
Leave a Comment