Pagini recente » Cod sursa (job #394092) | Cod sursa (job #275380) | Cod sursa (job #1263019) | Cod sursa (job #1931753) | Cod sursa (job #2959990)
#include <bits/stdc++.h>
using namespace std;
/// INPUT / OUTPUT
ifstream fin("lupu.in");
ofstream fout("lupu.out");
/// GLOBAL VARIABLES
int n, x, l;
vector<pair<int,int>>v;
inline bool compare(pair<int,int>x, pair<int,int>y)
{
if(x.second == y.second)
return x.first < y.first;
return x.second < y.second;
}
/// SOLUTION
inline void solve()
{
int ans = 0;
sort(v.rbegin(), v.rend(), compare);
for(int i = 0; i < v.size(); ++ i)
{
if(x >= v[i].first)
ans += v[i].second, x-=l;
}
fout << ans;
}
/// READING THE INPUT
int main()
{
ios::sync_with_stdio(false);
fin.tie(NULL);
fout.tie(NULL);
fin >> n >> x >> l;
for(int i = 1; i <= n; ++ i)
{
int n1, n2;
fin >> n1 >> n2;
v.push_back({n1,n2});
}
solve();
}