Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. //#include <ext/pb_ds/tree_policy.hpp>
  3. //#include <ext/pb_ds/assoc_container.hpp>
  4. using namespace std;
  5. //using namespace __gnu_pbds;
  6. #define ll long long int
  7. #define ull unsigned long long int
  8. #define ld long double
  9. #define fi first
  10. #define se second
  11. #define pb push_back
  12. #define pbb pop_back
  13. #define mp make_pair
  14. #define popcount __builtin_popcountll
  15. #define pii pair<int,int>
  16. #define all(x) x.begin(), x.end()
  17. #define uniq(x) x.erase(unique(x.begin(),x.end()),x.end())
  18. #define mem(array, value) memset(array, value, sizeof(array))
  19. #define lcm(a,b) (abs(a)/gcd(a,b))*abs(b)
  20. #define random(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
  21. #define PI 2*acos(0.0)
  22. #define EPS 1e-8
  23. #define line cout << "\n==========\n"
  24. #define fastRead ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
  25. #define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
  26. template <typename Arg1>
  27. void __f(const char* name, Arg1&& arg1){
  28. cerr << name << " : " << arg1 << "\n";
  29. }
  30. template <typename Arg1, typename... Args>
  31. void __f(const char* names, Arg1&& arg1, Args&&... args){
  32. const char* comma = strchr(names + 1, ',');
  33. cerr.write(names, comma - names) << " : " << arg1 << " , ";
  34. __f(comma + 1, args...);
  35. }
  36. //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
  37.  
  38. //int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; // 4 Direction
  39. //int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; // 8 Direction
  40. //int dx[] = {1, -1, 1, -1, 2, 2, -2, -2}, dy[] = {2, 2, -2, -2, 1, -1, 1, -1}; // Knight Direction
  41.  
  42. inline ll gcd(ll a, ll b){
  43. a = abs(a);
  44. b = abs(b);
  45. while (b){
  46. a = a % b;
  47. swap (a, b);
  48. }
  49. return a;
  50. }
  51. inline ll power(ll a, ll p){
  52. ll res = 1, x = a;
  53. while (p){
  54. if (p & 1){
  55. res = (res * x);
  56. }
  57. x = (x * x);
  58. p >>= 1;
  59. }
  60. return res;
  61. }
  62. inline ll mulmod(ll a, ll p, ll m){
  63. ll res = 0, x = a%m;
  64. while (p){
  65. if (p & 1){
  66. res = (res + x) % m;
  67. }
  68. x = (x << 1) % m;
  69. p >>= 1;
  70. }
  71. return res;
  72. }
  73. inline ll bigmod(ll a, ll p, ll m){
  74. ll res = 1 % m, x = a % m;
  75. while (p){
  76. if (p & 1){
  77. res = (res * x) % m;
  78. }
  79. x = (x * x) % m;
  80. p >>= 1;
  81. }
  82. return res;
  83. }
  84.  
  85. const int INF = 1e9+9;
  86.  
  87. const int nax = 2e5+5;
  88. ll ara[nax];
  89. int n;
  90. ll ans;
  91. ll mx = INF;
  92.  
  93. int main ()
  94. {
  95. #ifdef Lollipop
  96. freopen ("input.txt", "r", stdin);
  97. //freopen ("output.txt", "w", stdout);
  98. #endif
  99.  
  100. cin >> n;
  101. for (int i = 0; i<n; i++){
  102. cin >> ara[i];
  103. }
  104. for (int i = n-1; i>=0; i--){
  105. if (ara[i] < mx){
  106. ans += ara[i];
  107. mx = ara[i];
  108. }
  109. else{
  110. mx--;
  111. if (mx < 0){
  112. break;
  113. }
  114. ans += mx;
  115. }
  116. }
  117. cout << ans << endl;
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement