主要是学一下它的这个构造方法~看题不仔细 直接脑瘫
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;
ll a[N],b[N];
ll n,m;
ll sum;
ll ans;priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>q;
void solve()
{cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];q.push({a[i],i});sum+=a[i];ans = max(ans,a[i]);}ans = max((sum+m-1)/m,ans);vector<array<ll,4>>v;for(int i=1;i<=m;i++){if(!q.size())break;while(b[i]<ans&&q.size()){auto t = q.top();ll ts = t.first,id = t.second;q.pop();if(b[i]+ts<=ans){v.push_back({id,i,b[i],b[i]+ts});//cout<<id<<" "<<i<<" "<<b[i]<<" "<<b[i]+ts<<"\n";b[i]+=ts;}else{if(ans-b[i]!=0)v.push_back({id,i,b[i],ans});// cout<<id<<" "<<i<<" "<<b[i]<<" "<<ans<<"\n";q.push({ts-(ans-b[i]),id});break;}}}cout<<v.size()<<"\n";for(auto t:v)cout<<t[0]<<" "<<t[1]<<" "<<t[2]<<" "<<t[3]<<"\n";}int main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;_ = 1;while(_--)solve();
}
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;
ll a[N];
ll n,m;
ll sum;
ll ans;void solve()
{cin>>n>>m;for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];ans = max(ans,a[i]);}ans = max((sum+m-1)/m,ans);ll b = 1;vector<array<ll,4>>v;for(int i=1;i<=m;i++){ll rem = ans;while(b<=n&&rem){ll tem = min(a[b],rem);v.push_back({b,i,ans-rem,ans-rem+tem});rem-=tem,a[b]-=tem;if(!a[b])b++;}}cout<<v.size()<<"\n";for(auto t:v)cout<<t[0]<<" "<<t[1]<<" "<<t[2]<<" "<<t[3]<<"\n";}int main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;_ = 1;while(_--)solve();
}