1844C - Particles - CodeForces Solution


constructive algorithms greedy implementation math

Please click on ads to support us..

C++ Code:

/*
    || धर्मं चर। धर्मान्न प्रमदितव्यम् ||
*/

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ld = long double;
const ld Pi = 3.141592653589793238462643;
const ld e = 2.718281828459045235360;
const ll MOD = 100;

#define f(variable,s,e,j) for(ll variable = s ; variable < e ; variable+=j)
#define fr(variable,s,e,j) for(ll variable = s ; variable > e ; variable-=j)
#define test(n) while(n--)
#define trav(x,y) for(auto x : y)
#define endl '\n'

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mems(x,y) memset(x , y, sizeof(x));
#define pb(v) push_back(v);
#define pp pop_back();

#define MODadd(x,y) ((x % MOD) + (y % MOD) + MOD ) % MOD
#define MODsub(x,y) ((max(x,y) % MOD) - (min(x,y) % MOD) + MOD ) % MOD
#define MODmul(x,y) ((x % MOD) * (y % MOD)) % MOD

#ifndef vipplovve
#define debug(value) cerr << #value << " : " << value << endl;
#else
#define debug(value);
#endif

int main()
{
    #ifndef vipplovve
        freopen("errors.txt","w",stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    auto beg = high_resolution_clock::now();

    //Code Here.

    ll t;

    cin >> t;

    test(t)
    {
        ll len;

        cin >> len;

        ll data[len];

        ll EveSum = 0, OddSum = 0;

        f(x,0,len,1)
        {
            cin >> data[x];

            if(data[x] > 0)
            {
                if(x&1)
                    OddSum += data[x];

                else
                    EveSum += data[x];
            }
        }

        if(!EveSum && !OddSum)
            cout << *max_element(data,data+len) << endl;

        else
            cout << max(EveSum,OddSum) << endl;
    }

    auto end = high_resolution_clock::now();

    auto duration = duration_cast <microseconds> (end - beg);
    
    #ifndef vipplovve
        cerr << endl << "Time Taken : " << duration.count() / 1000 << " ms." << endl;
    #endif

    return 0;
}


Comments

Submit
0 Comments
More Questions

734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words
160A - Twins
1A - Theatre Square
1614B - Divan and a New Project
791A - Bear and Big Brother
1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality