Skip to content

Instantly share code, notes, and snippets.

@m4scosta
Created May 5, 2015 02:45
Show Gist options
  • Save m4scosta/65cf0303dd5ce828254b to your computer and use it in GitHub Desktop.
Save m4scosta/65cf0303dd5ce828254b to your computer and use it in GitHub Desktop.
20% WA
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef pair<int, int> jogo;
int main()
{
int n, g, s, r, pontos;
vector <int> jogos;
while (cin >> n >> g) {
jogos.clear();
pontos = 0;
for (int i = 0; i < n; ++i) {
cin >> s >> r;
int diff;
diff = s - r;
if (diff > 0) {
pontos += 3;
} else {
jogos.push_back(abs(diff));
}
}
int length = jogos.size();
sort(jogos.begin(), jogos.end());
for (int i = 0; i < length && g > 0; i++) {
if (jogos[i] == 0) {
pontos += 3;
g--;
} else {
if (g > jogos[i] + 1) {
pontos += 3;
g -= jogos[i] + 1;
} else if (g == jogos[i] + 1) {
pontos += 1;
g = 0;
}
}
}
cout << pontos << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment