fork download
  1. /*#pragma GCC optimize("Ofast,no-stack-protector")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  3. #pragma GCC optimize("unroll-loops")
  4. #pragma GCC optimize("fast-math")*/
  5. #include <iostream>
  6. #include <complex>
  7. #include <vector>
  8. #include <string>
  9. #include <algorithm>
  10. #include <cstdio>
  11. #include <numeric>
  12. #include <cstring>
  13. #include <ctime>
  14. #include <cstdlib>
  15. #include <set>
  16. #include <map>
  17. #include <unordered_map>
  18. #include <unordered_set>
  19. #include <list>
  20. #include <cmath>
  21. #include <bitset>
  22. #include <cassert>
  23. #include <queue>
  24. #include <stack>
  25. #include <deque>
  26. #include <random>
  27.  
  28. using namespace std;
  29.  
  30. #define pb push_back
  31. #define all(x) x.begin(), x.end()
  32. #define rall(x) x.rbegin(), x.rend()
  33. #define Str(x) to_string(x)
  34. #define len(s) (int)s.size()
  35.  
  36. typedef long long ll;
  37. typedef long double lld;
  38. typedef string str;
  39. typedef unsigned long long ull;
  40.  
  41. ll n, today, ans, arrive, came;
  42. string s, x;
  43.  
  44. void read()
  45. {
  46. cin >> n >> today;
  47. ans = today;
  48. getline(cin, s);
  49. for (int i = 1; i < n; ++i) {
  50. x.clear();
  51. getline(cin, s);
  52. for (int j = 0; j < s.size(); ++j) {
  53. if (s[j] == ' ') break;
  54. x += s[j];
  55. }
  56.  
  57. arrive = stoi(x);
  58. came = 0;
  59. today -= arrive;
  60. if (x.size() != s.size()) {
  61. x.clear();
  62. for (int j = s.size() - 1; j >= 0; --j) {
  63. if (s[j] == ' ') break;
  64. x = s[j] + x;
  65. }
  66. came = stoi(x);
  67. }
  68. today += came;
  69. //cout << s << " " << arrive << " " << came << " " << today << endl;
  70. ans = max(ans, today);
  71. }
  72. }
  73.  
  74. int main() {
  75. ios_base::sync_with_stdio(false);
  76. cin.tie(NULL);
  77. cout.tie(NULL);
  78. #ifdef LOCAL
  79. freopen("input.txt", "r", stdin);
  80. freopen("output.txt", "w", stdout);
  81. #endif
  82. read();
  83. cout << ans;
  84. return 0;
  85. }
  86.  
Success #stdin #stdout 0s 4156KB
stdin
5
0 
0 9
3 4
2 0
8
stdout
10