fork download
  1. #include <bits/stdc++.h>
  2. struct Amplifier{
  3. long long m, c;
  4. bool operator<(Amplifier &o){
  5. return o.m * c + o.c > m * o.c + c;
  6. }
  7. };
  8. // cb (ma - 1)
  9. int main() {
  10. std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);
  11. int n;
  12. std::cin >> n;
  13. Amplifier a[n];
  14. for(int i=0; i<n; ++i)
  15. std::cin >> a[i].m >> a[i].c;
  16. std::sort(a, a+n);
  17. long long ans{1};
  18. for(auto &[m, c] : a)
  19. ans = ans * m + c;
  20. std::cout << ans << '\n';
  21. }
Success #stdin #stdout 0s 5312KB
stdin
2
3 5
4 7
stdout
39