public static double Func(int i,int T){
		double result1=Double.MAX_VALUE,result2=Double.MAX_VALUE;
		
		if(i==n){return 0;}
		if(c[i]!=-1) return c[i];
		if(T==0){
			double temp=0;
			if(t[i] < (M-5)){
				temp= Math.pow((M-5) - (t[i]), 4);
			}
			result1 = temp+Func(i+1,0);
		}
		
		if(T+t[i] <= M){
			result2 = Func(i+1,T+t[i]);
		}
		else{
			double temp=0;
			if(T<(M-5)){
				temp= Math.pow((M-5) - T, 4);
			}
			result2 = temp + Func(i,0);
		}

		return Math.min(result1, result2);
	}