Skip to content

Instantly share code, notes, and snippets.

@modos
Created April 26, 2023 05:42
Show Gist options
  • Save modos/151986c5cf30c1bffbd0b7fb717c1578 to your computer and use it in GitHub Desktop.
Save modos/151986c5cf30c1bffbd0b7fb717c1578 to your computer and use it in GitHub Desktop.
انرژی خور
/// In The Name Of God
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 100010;
pair<int,int> a[MAX_N];
int main(){
int n;
long long k;
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a,a+n);
for(int i = 0; i < n; i++)
if(k >= a[i].first) /// we can eat i-th fruit
if(a[i].second > a[i].first) /// we gain positive energy by eating this fruit
k += a[i].second - a[i].first; /// eat -> lose a[i].first energy ans gain a[i].second
cout << k << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment