962A - Equator - CodeForces Solution


implementation *1300

Please click on ads to support us..

Python Code:

n=int(input())
a=list(map(int,input().split()))
b=sum(a)
cnt=0
for i in range(n):
    cnt+=a[i]
    if(cnt>=b/2):
        print(i+1)
        break

C++ Code:

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ull unsigned long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define f(n) for (int i = 0; i < n; i++)
#define PI 3.1415926536
#define MOD 1073741824
const ll INF = 1e9 + 7;

int fact(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * fact(n - 1);
}
int countDivisors(ll n)
{
    int cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
// Palindrome Check
int isPalindrome(string s)
{
    // Start from leftmost and rightmost corners of str
    int l = 0;
    int h = s.length() - 1;

    // Keep comparing characters while they are same
    while (h > l)
    {
        if (s[l++] != s[h--])
        {
            return 0;
        }
    }
    return 1;
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
bool Primecheck(ll n)
{
    if (n == 1)
        return false;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}
vector<ll> primes;
vector<ll> findPrimes()
{
    for (int i = 2; i < 1e6; i++)
    {
        if (Primecheck(i))
            primes.pb(i);
    }
}
bool comp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    if (a.first != b.first)
    {
        return (a.first < b.first);
    }
    else
    {
        return (a.second > b.second);
    }
}
int highestPowerof2(int n)
{
    int res = 0;
    for (int i = n; i >= 1; i--)
    {
        // If i is a power of 2
        if ((i & (i - 1)) == 0)
        {
            res = i;
            break;
        }
    }
    return res;
}

ll bs_sqrt(ll x)
{
    ll left = 0, right = 2000000123;
    while (right > left)
    {
        ll mid = (left + right) / 2;

        if (mid * mid > x)
            right = mid;
        else
            left = mid + 1;
    }
    return left - 1;
}
void subString(char str[], int n)
{
    // Pick starting point
    for (int len = 1; len <= n; len++)
    {
        // Pick ending point
        for (int i = 0; i <= n - len; i++)
        {
            //  Print characters from current
            // starting point to current ending
            // point.
            int j = i + len - 1;
            for (int k = i; k <= j; k++)
                cout << str[k];

            cout << endl;
        }
    }
}

int countUnsetBits(ll n)
{
    ll x = n;

    // Make all bits set MSB
    // (including MSB)

    // This makes sure two bits
    // (From MSB and including MSB)
    // are set
    n |= n >> 1;

    // This makes sure 4 bits
    // (From MSB and including MSB)
    // are set
    n |= n >> 2;

    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;

    // Count set bits in toggled number
    return __builtin_popcountll(x ^ n);
}
long long binpow(long long a, long long b, long long m)
{
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2, m);
    if (b % 2)
        return ((res * res) % m * a) % m;
    else
        return (res * res) % m;
}
vector<int> decToBinary(int n)
{
    vector<int> binum;
    // Size of an integer is assumed to be 32 bits
    for (int i = 32; i >= 0; i--)
    {
        int k = n >> i;
        if (k & 1)
            binum.pb(1);
        else
            binum.pb(0);
    }
    return binum;
}
ll binaryToDecimal(int ans[])
{

    int dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    int base = 1;

    int len = 32;
    for (int i = len - 1; i >= 0; i--)
    {
        if (ans[i] == 1)
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
bool isPerfectSquare(long double x)
{
    // Find floating point value of
    // square root of x.
    if (x >= 0)
    {

        long long sr = sqrt(x);

        // if product of square root
        // is equal, then
        // return T/F
        return (sr * sr == x);
    }
    // else return false if n<0
    return false;
}
map<ll, ll> mmm;
void primeFactors(int n)
{
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        mmm[2]++;
        n = n / 2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            mmm[i]++;
            n = n / i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        mmm[n]++;
}

ll getSum(ll n)
{
    int sum = 0;
    while (n != 0)
    {
        sum = sum + n % 10;
        n = n / 10;
    }
    return sum;
}
vector<char> vi;
string LCSubStr(string X, string Y)
{
    // Find length of both the strings.
    int m = X.length();
    int n = Y.length();
 
    // Variable to store length of longest
    // common substring.
    int result = 0;
 
    // Variable to store ending point of
    // longest common substring in X.
    int end;
 
    // Matrix to store result of two
    // consecutive rows at a time.
    int len[2][n + 1];
 
    // Variable to represent which row of
    // matrix is current row.
    int currRow = 0;
 
    // For a particular value of i and j,
    // len[currRow][j] stores length of longest
    // common substring in string X[0..i] and Y[0..j].
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 || j == 0) {
                len[currRow][j] = 0;
            }
            else if (X[i - 1] == Y[j - 1]) {
                len[currRow][j] = len[1 - currRow][j - 1] + 1;
                if (len[currRow][j] > result) {
                    result = len[currRow][j];
                    end = i - 1;
                }
            }
            else {
                len[currRow][j] = 0;
            }
        }
 
        // Make current row as previous row and
        // previous row as new current row.
        currRow = 1 - currRow;
    }
 
    // If there is no common substring, print -1.
    if (result == 0) {
        return "";
    }
    return X.substr(end - result + 1, result);
}
void solve()
{  
    ll n;cin>>n;
    ll a[n],sum=0,temp=0;
    f(n){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%2==0)sum/=2;
    else sum=(sum+1)/2;
    f(n){
        temp+=a[i];
        if(temp>=sum){
            cout<<i+1<<endl;
            return;
        }
    }

   
    }
    



int main()

{
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        solve();}

     
}


Comments

Submit
0 Comments
More Questions

Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array
852. Peak Index in a Mountain Array
461. Hamming Distance
1748. Sum of Unique Elements
897. Increasing Order Search Tree
905. Sort Array By Parity
1351. Count Negative Numbers in a Sorted Matrix
617. Merge Two Binary Trees
1450. Number of Students Doing Homework at a Given Time
700. Search in a Binary Search Tree
590. N-ary Tree Postorder Traversal
589. N-ary Tree Preorder Traversal