Cod sursa(job #2930639)

Utilizator LukyenDracea Lucian Lukyen Data 29 octombrie 2022 01:06:28
Problema Buline Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>
using namespace std;

#define vecLen 200001
ifstream fin("buline.in");
ofstream fout("buline.out");

int vec[vecLen];
int main()
{
  cin.rdbuf(fin.rdbuf());
  cout.rdbuf(fout.rdbuf());

  int n, x, sign, sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> x;
    cin >> sign;
    vec[i] = x;
    if (!sign)
      vec[i] *= -1;
    sum += vec[i];
  }

  tuple<int, int, int> cMax{1, 1, vec[1]}, tMax{1, 1, vec[1]}, cMin{1, 1, vec[1]}, tMin{1, 1, vec[1]};
  for (int i = 2; i <= n; i++)
  {
    if (vec[i] > get<2>(cMax) + vec[i])
      get<2>(cMax) = vec[i], get<0>(cMax) = i, get<1>(cMax) = 1;
    else
      get<2>(cMax) += vec[i], get<1>(cMax)++;

    if (vec[i] < get<2>(cMin) + vec[i])
      get<2>(cMin) = vec[i], get<0>(cMin) = i, get<1>(cMin) = 1;
    else
      get<2>(cMin) += vec[i], get<1>(cMin)++;

    if (get<2>(cMax) > get<2>(tMax))
      tMax = cMax;
    if (get<2>(cMin) < get<2>(tMin))
      tMin = cMin;
  }

  if (get<2>(tMax) > sum - get<2>(tMin))
    cout << get<2>(tMax) << " " << get<0>(tMax) << " " << get<1>(tMax);
  else
    cout << sum - get<2>(tMin) << " " << get<0>(tMin) + get<1>(tMin) << " " << n - get<1>(tMin);

  return 0;
}