Pagini recente » Cod sursa (job #1512954) | Cod sursa (job #1112886) | Cod sursa (job #2356939) | Cod sursa (job #2675308) | Cod sursa (job #2073911)
#include<bits/stdc++.h>
using namespace std;
ifstream f("bilute.in");
ofstream g("bilute.out");
int n;
int va[30002];
int dt[30002];
int sum;
int min1,opt1;
int sst,sdr;
int nrst,nrdr;
void lily()
{
f>>n;
for(int i=1;i<=n;++i)
{
f>>va[i]>>dt[i];
sum+=va[i]*dt[i];
}
for(int i=n;i>1;--i)
sdr+=va[i]*(i-1),nrdr+=va[i];
min1=sum+sdr-va[1]*dt[1];
opt1=1;
}
void rose()
{
for(int i=2;i<=n;++i)
{
nrst+=va[i-1];
sst+=nrst;
sdr-=nrdr;
nrdr-=va[i];
if(sum+sst+sdr-va[i]*dt[i]<min1)
min1=sum+sst+sdr-va[i]*dt[i],opt1=i;
}
g<<opt1<<" "<<min1<<'\n';
}
int main()
{
lily();rose();
return 0;
}