Cod sursa(job #2859400)

Utilizator Luca_Miscocilucainfoarena Luca_Miscoci Data 1 martie 2022 11:54:09
Problema Bilute Scor 0
Compilator cpp-64 Status done
Runda tagalaibas Marime 0.91 kb
#include <fstream>
#define NMAX 30000
#define int long long
using namespace std;
int value;
struct prob{
  int c, l;

}v[NMAX + 1];

int cost;
int sp[NMAX + 1];

/*

cost[i][j] = costul de vopsire al lui I pentru nuanta J ABANDONATA
i - 1 = 0 ->> skip
*/

signed main(){

  ifstream fin ("bilute.in");
  ofstream fout ("bilute.out");

  int n;
  fin >> n;
  sp[0] = 0;
  for (int i = 1; i <= n; i++){
    fin >> v[i].c >> v[i].l;
    sp[i] = sp[i - 1] + v[i].c;

    if (i == 1)
      continue;

    cost += v[i].c * v[i].l + v[i].c * (value = (i >= 1) ? (i - 1) : (1 - i));

  }
  int minn = 1e9;
  int ras = 1e2;
  for (int i = 2; i <= n; i++){
    cost -= (sp[n] - sp[i]);
    cost += sp[i - 1];
    cost += (v[i - 1].c * v[i - 1].l);
    cost -=(v[i].c * (v[i].l + 1));
    if (cost < minn)
      ras = min(ras,i) , minn = cost;
  }
  fout << ras << " " << minn;
  return 0;
}