Created
April 26, 2023 05:42
-
-
Save modos/151986c5cf30c1bffbd0b7fb717c1578 to your computer and use it in GitHub Desktop.
انرژی خور
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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