Advertisement
a53

fractii3

a53
Sep 22nd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <fstream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. ifstream fin ("fractii3.in");
  6. ofstream fout ("fractii3.out");
  7.  
  8. int n, k, a, b, i, sol;
  9.  
  10. queue <pair <int, int> > Q;
  11.  
  12. int frcmp(pair <int, int> a, pair <int, int> b) {
  13. if (1LL * a.first * b.second < 1LL * b.first * a.second)
  14. return -1;
  15. if (1LL * a.first * b.second == 1LL * b.first * a.second)
  16. return 0;
  17. return 1;
  18. }
  19.  
  20. int main() {
  21. fin >> n >> k;
  22. for (i = 0; i < n; ++i) {
  23. fin >> a >> b;
  24. if (a <= b) {
  25. Q.push(make_pair (a + b, b));
  26. continue;
  27. }
  28. if (!Q.size())
  29. break;
  30. while (frcmp (Q.front(), make_pair (a, b)) < 0)
  31. Q.pop();
  32. if (frcmp (Q.front(), make_pair (a, b)) == 0) {
  33. Q.push(make_pair (Q.front().first + Q.front().second, Q.front().second));
  34. Q.pop();
  35. }
  36. }
  37. if (!Q.size()) {
  38. fout << "failed at " << i << "\n";
  39. return 0;
  40. }
  41. fout << Q.size();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement