Advertisement
a53

bile2

a53
Jul 9th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream fin ("bile2.in");
  5. ofstream fout ("bile2.out");
  6.  
  7. const int N = 1e5 + 5;
  8.  
  9. long long h[N], k[N], n, m, x, t;
  10.  
  11. #define max(x,y) ((x)<(y)?(y):(x))
  12.  
  13. int main() {
  14. fin >> n >> m;
  15. for (int i = 1; i <= n; ++i)
  16. fin >> h[i] >> k[i];
  17. for (int i = 0; i < m; ++i) {
  18. fin >> x >> t;
  19. int crt = h[x], height = h[x];
  20. if (t <= h[x]) {
  21. fout << h[x] - t << "\n";
  22. continue;
  23. }
  24. t -= h[x];
  25. height = 0;
  26. crt -= k[x];
  27. while (t && crt) {
  28. if (t <= crt) {
  29. height += t;
  30. t = 0;
  31. }
  32. else {
  33. t -= crt;
  34. height = crt;
  35. }
  36. if (!t)
  37. break;
  38. if (t <= crt) {
  39. height -= t;
  40. t = 0;
  41. }
  42. else {
  43. t -= crt;
  44. height = 0;
  45. }
  46. crt = max(0, crt - k[x]);
  47. }
  48. fout << height << "\n";
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement