Codeforces Round #849 (Div. 4) 1791E - Negatives and Positives Solution
Problem Link : https://codeforces.com/contest/1791/problem/E
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t ;
- cin >> t ;
- while ( t-- ){
- int n ;
- cin >> n ;
- long long a[n+3] , cnt = 0 ;
- long long sum = 0 , mn = 1e9 ;
- for ( int i = 0 ; i < n ; i++ ){
- cin >> a[i] ;
- sum += abs(a[i]) ;
- mn = min ( mn , abs(a[i]) ) ;
- if ( a[i] < 0 ) cnt++;
- }
- if ( cnt % 2 == 0 ) cout << sum << endl;
- else {
- cout << sum - (mn+mn)<< endl;
- }
- }
- }
No comments