Cod sursa(job #465414)

Utilizator cristian9Cristian Zloteanu cristian9 Data 24 iunie 2010 11:02:46
Problema Cuburi2 Scor 6
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<stdio.h>

int main(){
	freopen ("cuburi2.in", "r", stdin);
	freopen ("cuburi2.out", "w", stdout);

	int n, m, i, v[250000], x, y, j, z, s=0, k, kmax; 
	long smin=2000000;

	scanf("%d %d ", &n, &m);

	for(i=1; i<=n; i++){
		scanf("%d ", &v[i]);
	}

	for(i=1; i<=m; i++){
		scanf("%d %d ", &x, &y);
		for(j=x; j<=y; j++){
			for(z=x; z<=y; z++){
				if(z>j){
					s=s+(z-j)*v[z];
					k=j;
				}
				else{
					s=s+(j-z)*v[z];
					k=j;
				}
			}
			if(s<=smin){
				smin=s;
				kmax=k;
				//printf("%d\n", smax);
			}
			s=0;
		}
		printf("%d %lld\n", kmax, smin);
    smin=2000000;
	}

	return 0;
}