EPS/2024/04/29-04-24-Partiel/c2.cpp

41 lines
964 B
C++
Raw Permalink Normal View History

2024-05-06 15:21:59 +02:00
/* PARTIEL TEMPS */
// Runtime error: doit-être relative au temps d'exécution,
// Je n'ai pas eu le temps d'optimiser plus
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
int main() {
int n;
vector<pair<int, int>> discos;
int input1, input2;
cin >> n;
for (int i=0; i < n; i++) {
cin >> input1;
cin >> input2;
discos.push_back(pair<int, int>(input1, input2));
}
// On trie par ordre lexicographique sur (-x[0], x[1])
sort(
begin(discos),
end(discos),
[](pair<int, int> a, pair<int, int> b) {
return !(-a.second>-b.second || (a.second==b.second && a.first > b.first));
}
);
int discount = 1;
int balance = 0;
// On calcule le discount et les achats
for (int i=0; i < n; i++) {
balance -= discos[i].first / discount;
discount *= discos[i].second;
}
cout << (-balance) << "\n";
}