Editorial for CCC '17 S1 - Sum Game


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Kirito

Keep track of the sum of the scores for both teams, and record the index if the sums are the same.

Time Complexity: \mathcal O(N)

Sample Solution — D

import std.stdio;

int N, ans;
int[100004] r1, r2;
long s1, s2;
void main() {
    scanf("%d", &N);
    for(int i=0;i<N;i++)
        scanf("%d", &r1[i]);
    for(int i=0;i<N;i++)
        scanf("%d", &r2[i]);
    for(int i=0;i<N;i++) {
        s1 += r1[i];
        s2 += r2[i];
        if(s1 == s2) ans = i + 1;
    }
    printf("%d", ans);
}

Comments


  • -2
    hello12_2015  commented on Aug. 25, 2017, 1:11 p.m.

    is this in java or javascript?


    • -1
      wleung_bvg  commented on Aug. 25, 2017, 1:18 p.m.

      This is in the D programming language. It's similar to C++.


      • 4
        Roronoa_Zoro1540  commented on July 16, 2019, 11:42 a.m.

        Oh because C + 1 is D ohhh


        • -6
          PayOrWithdraw  commented on July 16, 2019, 12:39 p.m.

          This comment is hidden due to too much negative feedback. Click here to view it.