In this HackerEarth Determine, the winner problem solution Assume there are two programmers with their hacker names as "Flash" and "Cisco". They both took part in a contest. The rules of the contest are:
  1. There will be 4 questions to solve, P, Q, R and S.
  2. Initial score (before the start of the contest) of the 4 problems is s_p, s_q, s_r and s_s.
  3. After each minutes, the score of the questions, P, Q, R and S, will decrease by  d_p, d_q, d_r and d_s respectively. The score cannot decrease below half (integer division) of the initial score for each question i.e. at a particular time, the score of the problems will be a maximum of half of the initial score and the decreased score.
Flash submitted the solutions of the questions at time f_p, f_q, f_r and f_s. Cisco submitted the solutions of the questions at time c_p, c_q, c_r and c_s. Your task is to find winner of contest. The winner is the one who has more score. If the score of both the programmers is same, then winner will be the one who took less time to solve all the questions. If both the problems have same score and took same time to solve the questions, then print Tie.


HackerEarth Determine the winner problem solution


HackerEarth Determine the winner problem solution.

import java.util.*;
import java.io.*;

public class Problem {

  public static void main(String[] args) throws IOException
  {
    Scanner sc=new Scanner(System.in);
    int t=sc.nextInt();
    StringBuilder sb=new StringBuilder();
    while(t-->0){
    long  s_p=sc.nextLong();
    long  s_q=sc.nextLong();
    long  s_r=sc.nextLong();
    long  s_s=sc.nextLong();

    long d_p=sc.nextLong();
    long d_q=sc.nextLong();
    long d_r=sc.nextLong();
    long d_s=sc.nextLong();
      
    long f_p=sc.nextLong();
    long f_q=sc.nextLong();
    long f_r=sc.nextLong();
    long f_s=sc.nextLong();
    
    long c_p=sc.nextLong();
    long c_q=sc.nextLong();
    long c_r=sc.nextLong();
    long c_s=sc.nextLong();
      
        long  sum1 = 0;
        long maxi1 = 0;

        /**
        * Score for any question can only decrease till half of initial value.
        * So we will take always maximum of values after time d_a which will be da*ra and half of the initail a/2
        * This is the case for all the questions.
        **/

        maxi1 = max(maxi1 , f_p);
        sum1 += max(s_p/2 ,s_p - f_p*d_p);
        maxi1 = max(maxi1 , f_q);
        sum1 += max(s_q/2 ,s_q - f_q*d_q);
        maxi1 = max(maxi1 , f_r);
        sum1 += max(s_r/2 , s_r - f_r*d_r);
        maxi1 = max(maxi1 , f_s);
        sum1 += max(s_s/2 , s_s - f_s*d_s);

      long sum2 = 0;
      long maxi2 = 0;
        maxi2 = max(maxi2 , c_p);
      sum2 += max(s_p/2 , s_p - c_p*d_p);
        maxi2 = max(maxi2 , c_q);
        sum2 += max(s_q/2 , s_q - c_q*d_q);
        maxi2 = max(maxi2 , c_r);
        sum2 += max(s_r/2 , s_r - c_r*d_r);
        maxi2 = max(maxi2 , c_s);
        sum2 += max(s_s/2 , s_s - c_s*d_s);


        if(sum1 > sum2)
            sb.append("Flash\n");
        else if(sum1 < sum2)
            sb.append("Cisco\n");
        else if(maxi1 < maxi2)
          sb.append("Flash\n");
        else if(maxi1 > maxi2)
          sb.append("Cisco\n");
        else
          sb.append("Tie\n");
      
    }
    System.out.println(sb);
    
    
    
}
    private static long max(long a,long b){
      return Math.max(a, b);
    }

}


Second solution

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define sz size()
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define REP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define REPI(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define REPITER(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define pi 3.141592653589793

using namespace std;

template<class T> inline T gcd(T a, T b) { while(b) b ^= a ^= b ^= a %= b; return a; }
template<class T> inline T mod(T x) { if(x < 0) return -x; else return x; }

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII > PPII;
typedef vector< PII > VPII;
typedef vector< PPII > VPPI;

const int MOD = 1e9 + 7;
const int INF = 1e9;
ll a[5][5], score[2], tim[2];

int main(int argc, char* argv[]) {
    if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
    if(argc == 3) freopen(argv[2], "w", stdout);
    ios::sync_with_stdio(false);
    int t;
    assert(cin >> t);
    assert(1 <= t and t <= 100000);
    while (t--) {
        score[0] = score[1] = 0;
        tim[0] = tim[1] = 0;
        REP(i, 0, 4, 1) {
            REP(j, 0, 4, 1) {
                assert(cin >> a[i][j]);
                if (i == 0) assert(100 <= a[i][j] and a[i][j] <= 1000000);
                else assert(0 <= a[i][j] and a[i][j] <= 1000000);
            }
        }
        REP(i, 0, 4, 1) {
            int x = a[0][i] / 2;
            if (a[1][i] > 0) a[4][i] = x / a[1][i] + ((x % a[1][i]) ? 1 : 0);
            else a[4][i] = max(a[2][i], a[3][i]) + 1;
            if (a[4][i] <= a[2][i]) score[0] += (a[0][i] / 2);
            else score[0] += (a[0][i] - a[1][i]*a[2][i]);
            if (a[4][i] <= a[3][i]) score[1] += (a[0][i] / 2);
            else score[1] += (a[0][i] - a[1][i]*a[3][i]);
            tim[0] = max(tim[0], a[2][i]);
            tim[1] = max(tim[1], a[3][i]);
        }
        if (score[0] < score[1]) cout << "Cisco" << endl;
        else if (score[0] > score[1]) cout << "Flash" << endl;
        else if (tim[0] > tim[1]) cout << "Cisco" << endl;
        else if (tim[0] < tim[1]) cout << "Flash" << endl;
        else cout << "Tie" << endl;
    }
    assert(!(cin >> t));
    return 0;
}