求助E题
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
static BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
static PrintWriter cout=new PrintWriter(new OutputStreamWriter(System.out));
static StreamTokenizer st=new StreamTokenizer(cin);
static int MAXN=100001;
static long a[]=new long[MAXN];
static int n,m;
public static void main(String[] args)throws IOException {
n=nextInt();
m=nextInt();
long sum=0,max=0;
for(int i=1;i<=n;++i) {
a[i]=nextLong();
sum+=a[i];
max=Math.max(max, a[i]);
}
max=Math.max(max, sum/m+(sum%m==0?0:1));
StringBuilder sb=new StringBuilder();
long time=0;
for(int i=1,idx=1;i<=m&&idx<=n;) {
sb.setLength(0);
long cost=Math.min(max-time,a[idx]);
sb.append(idx+" "+i+" "+time+" "+(time+cost));
cout.println(sb.toString());
time=(cost+time)%max;
if(time==0) i++;
a[idx]-=cost;
if(a[idx]==0) idx++;
}
end();
}
public static void end() throws IOException {
cout.flush();
cout.close();
cin.close();
}
public static double nextDouble()throws IOException{
st.nextToken();
return st.nval;
}
public static int nextInt() throws IOException {
st.nextToken();
return (int)st.nval;
}
public static long nextLong()throws IOException{
st.nextToken();
return (long) st.nval;
}
public static String next()throws IOException{
st.nextToken();
return st.sval;
}
}