-
-
Save fredbr/11aede4a1a57b87d9c221dda6f8a2b5f to your computer and use it in GitHub Desktop.
Bolsas
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
#include <bits/stdc++.h> | |
#define D first | |
#define T second | |
using namespace std; | |
typedef pair<int, int> pii; | |
const int maxn = 10010; | |
pii v[maxn]; | |
int main() | |
{ | |
int n; | |
cin >> n; | |
for (int i = 0; i < n; i++) { | |
cin >> v[i].T >> v[i].D; | |
} | |
sort(v, v + n); | |
long long s = 0; | |
long long matraso = 0; | |
for (int i = 0; i < n; i++) { | |
s += v[i].T; | |
if (s > v[i].D) matraso = max(matraso, s - v[i].D); | |
} | |
cout << matraso << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment