View Code of Problem 3699

#include<bits/stdc++.h>
#define f(s,v) for(int v=0;v<=s;++v)
using namespace std;
struct node{
	int p,x;
};
int main(){
	int L,N;
	while(cin>>L>>N){
		int a[L+1];
		node k[N];
		memset(a,0,sizeof(a));
		f(N-1,i)
		scanf("%d",&k[i].p);
		f(N-1,i)
		scanf("%d",&k[i].x);
		int maxn=0x3f3f3f3f,ans;
		f(L,i){
			f(N-1,m)
				a[i]+=(max(0,k[m].x-abs(k[m].p-i)));	
			if(maxn>a[i]){
				maxn=a[i];
				ans=i;
			}
		}
		printf("%d\n%d\n",ans,a[ans]);
	}
}

Double click to view unformatted code.


Back to problem 3699