Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. //============================================================================
  2. // Name        : HelloWorld.cpp
  3. // Author      : smalinux
  4. // Version     :
  5. // Copyright   : Your copyright notice
  6. // Description : Hello World in C++, Ansi-style
  7. //============================================================================
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #include<iomanip>
  12. using namespace std;
  13.  
  14.  
  15.  
  16. int main() {
  17.     // ----------------------------------------------------------------------
  18.  
  19.     unsigned long long int N = 0;
  20.     long long int arr[100000];
  21.     long long int sum = 0;
  22.  
  23.     // - Insertion
  24.     cin >> N;
  25.     if(N >= 1 && N <= 1e5)
  26.         for(unsigned long long int i = 0; i < N; i++)
  27.             cin>> arr[i];
  28.  
  29.     // - Output
  30.     for(unsigned long long int i = 0; i < N; i++) {
  31.         if(arr[i] < -1e9 || arr[i] > 1e9 ) return -1;
  32.         sum += arr[i];
  33.     }
  34.  
  35.     // absolute sum
  36.     if(sum < 0)
  37.         sum *= -1;
  38.  
  39.     cout << sum;
  40.  
  41.     // ----------------------------------------------------------------------
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement