Skip to content

Instantly share code, notes, and snippets.

@fredbr
Created May 2, 2018 23:11
Show Gist options
  • Save fredbr/11aede4a1a57b87d9c221dda6f8a2b5f to your computer and use it in GitHub Desktop.
Save fredbr/11aede4a1a57b87d9c221dda6f8a2b5f to your computer and use it in GitHub Desktop.
Bolsas
#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