Codeforces Round 912 (Div. 2) 1903C - Theofanis' Nightmare Solution



 Problem Link :  https://codeforces.com/contest/1903/problem/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ; cin >> n ;
  11. int a[n+2] ;
  12. for ( int i = 0 ; i < n ; i++){
  13. cin >> a[i] ;
  14. }
  15. long long suf[n+1] = {0};
  16. for ( int i = n - 1 ; i >= 0 ; i--){
  17. suf[i] = a[i] + suf[i+1] ;
  18. }
  19. long long ans = suf[0] ;
  20. for ( int i = 1 ; i < n ; i++){
  21. if(suf[i] > 0){
  22. ans += suf[i] ;
  23. }
  24. }
  25. cout << ans <<'\n';
  26. }
  27. return 0 ;
  28. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.