Pagini recente » Cod sursa (job #1646723) | Cod sursa (job #2333220) | Cod sursa (job #326523) | Cod sursa (job #160023) | Cod sursa (job #2666432)
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define bool char
#define MAXLOG10 18
#define BUFSIZE (128 * 1024)
FILE *in, *out;
long long p10[MAXLOG10+1];
long long rpos;
char rbuf[BUFSIZE];
long long wpos;
char wbuf[BUFSIZE];
static inline void init() {
long long i;
in=fopen("euro.in","r");
rpos=BUFSIZE - 1;
out=fopen("euro.out","w");
wpos=0;
p10[0]=0;
p10[1]=1;
for(i=2; i<=MAXLOG10; i++)
p10[i]=p10[i-1]*10LL;
return;
}
static inline char readchar() {
if (!(rpos=((rpos+1)&(BUFSIZE - 1))))
fread(rbuf,1,BUFSIZE,in);
return rbuf[rpos];
}
static long long getint() {
long long ch,rez=0,semn=1;
while(isspace(ch=readchar()));
if (ch=='-') {
semn=-1;
ch=readchar();
}
do
rez=10*rez+ch-'0';
while(isdigit(ch=readchar()));
return semn*rez;
}
static inline void writechar( char ch ) {
wbuf[wpos]=ch;
if (!(wpos=((wpos+1)&(BUFSIZE-1))))
fwrite(wbuf,1,BUFSIZE,out);
}
static void putint(long long x) {
long long i,cf;
if (x<0) {
writechar('-');
x=-x;
}
i=MAXLOG10;
while(p10[i]>x)
i--;
if (i==0)
writechar('0');
else {
do {
cf='0';
while(p10[i]<=x) {
x-=p10[i];
cf++;
}
writechar(cf);
} while(--i>0);
}
writechar(' ');
// writechar('\n') separatorul numerelor poate sa difere
}
static inline void terminate() {
writechar('\n');
fwrite(wbuf,1,wpos,out);
fclose(in);
fclose(out);
}
static inline long long min(long long a,long long b) {
return a<b?a:b;
}
static inline long long max(long long a, long long b) {
return b<a?a:b;
}
long long sum[34568];
struct data {
long long val,poz;
} deque[65536];
struct data makedata(long long val, long long poz) {
struct data rez;
rez.val=val;
rez.poz=poz;
return rez;
}
long long left,right;
static inline void popleft() {
left=((left+1)&65535);
}
static inline void popright() {
right=((right-1)&65535);
}
static inline void push(struct data x) {
deque[right]=x;
right=((right+1)&65535);
}
static inline struct data topleft() {
return deque[left];
}
static inline struct data topright() {
return deque[(right-1)&65535];
}
static inline long long empty() {
return left==right;
}
static void insert(struct data x) {
while(!empty() && topright().val>x.val)
popright();
push(x);
return;
}
signed main() {
init();
long long n,t,poz,total;
n=getint();
t=getint();
for(int i=1; i<=n; i++)
sum[i]=getint()+sum[i-1];
for(int i=n-1; i>=0; i--)
insert(makedata(sum[i],i));
poz=n;
total=0;
while(poz!=0) {
total+=poz*(sum[poz]-topleft().val)-t;
poz=topleft().poz;
popleft();
}
putint(total);
terminate();
return 0;
}