Language: C++

//AcFreak

#include<bits/stdc++.h>
#define lint long long int 

using namespace std;

struct point
{
      lint x,y,z; 
};

bool funx(point a,point b)
{
      return a.x<b.x;
}
bool funy(point a,point b)
{
      return a.y<b.y;
}
bool funz(point a,point b)
{
      return a.z<b.z;
}
bool funxx(point a,point b)
{
      if(a.x!=b.x)
      return a.x<b.x;
      else
       return a.y<b.y;
      
}
bool funyy(point a,point b)
{
      if(a.y!=b.y)
      return a.y<b.y;
      else
      return a.z<b.z;
}
bool funzz(point a,point b)
{
      if(a.z!=b.z)
      return a.z<b.z;
      else
       return a.x<b.x;
}

bool funs(point a,point b)
{
      return (a.x+a.y+a.z)<(b.z+b.x+b.y);
}
int main()
{
      lint n,m;
      cin>>n>>m;
      lint a,b,c;
      
      lint i;
      vector<point >arr(n);
      for(i=0;i<n;i++)
      {
            cin>>a>>b>>c;
            arr[i].x=a;
            arr[i].y=b;
            arr[i].z=c;
      }
      
      vector<point >xx(arr),yy(arr),zz(arr),ss(arr);
      
      sort(xx.begin(),xx.end(),funx);
      sort(yy.begin(),yy.end(),funy);
      sort(zz.begin(),zz.end(),funz);
      
       sort(xxx.begin(),xxx.end(),funxx);
      sort(yyy.begin(),yyy.end(),funyy);
      sort(zzz.begin(),zzz.end(),funzz);
      
      sort(ss.begin(),ss.end(),funs);

      
     /* for(i=0;i<n;i++)
      {
            cout<<yy[i].x<<" "<<yy[i].y<<" "<<yy[i].z<<endl;
      }*/
      lint ans=0;
      lint gx=0,gy=0,gz=0;
      for(i=0;i<m;i++)
      {
            gx+=xx[i].x;
            gy+=xx[i].y;
            gz+=xx[i].z;
      }
       ans=max(ans,(abs(gx)+abs(gy)+abs(gz)));
            
      for(i;i<n;i++)
      {
           
             gx+=xx[i].x;
            gy+=xx[i].y;
            gz+=xx[i].z;
             gx-=xx[i-m].x;
            gy-=xx[i-m].y;
            gz-=xx[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      gx=0;
      gy=0;
      gz=0;
       for(i=0;i<m;i++)
      {
            gx+=yy[i].x;
            gy+=yy[i].y;
            gz+=yy[i].z;
      }
       ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      for(i;i<n;i++)
      {
           
             gx+=yy[i].x;
            gy+=yy[i].y;
            gz+=yy[i].z;
             gx-=yy[i-m].x;
            gy-=yy[i-m].y;
            gz-=yy[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      
      gx=0;
      gy=0;
      gz=0;
       for(i=0;i<m;i++)
      {
            gx+=zz[i].x;
            gy+=zz[i].y;
            gz+=zz[i].z;
      }
       ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      for(i;i<n;i++)
      {
           
             gx+=zz[i].x;
            gy+=zz[i].y;
            gz+=zz[i].z;
             gx-=zz[i-m].x;
            gy-=zz[i-m].y;
            gz-=zz[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      
      
      
      
      gx=0,gy=0,gz=0;
      for(i=0;i<m;i++)
      {
            gx+=xxx[i].x;
            gy+=xxx[i].y;
            gz+=xxx[i].z;
      }
       ans=max(ans,(abs(gx)+abs(gy)+abs(gz)));
            
      for(i;i<n;i++)
      {
           
             gx+=xxx[i].x;
            gy+=xxx[i].y;
            gz+=xxx[i].z;
             gx-=xxx[i-m].x;
            gy-=xxx[i-m].y;
            gz-=xxx[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      gx=0;
      gy=0;
      gz=0;
       for(i=0;i<m;i++)
      {
            gx+=yyy[i].x;
            gy+=yyy[i].y;
            gz+=yyy[i].z;
      }
       ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      for(i;i<n;i++)
      {
           
             gx+=yyy[i].x;
            gy+=yyy[i].y;
            gz+=yyy[i].z;
             gx-=yyy[i-m].x;
            gy-=yyy[i-m].y;
            gz-=yyy[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      
      gx=0;
      gy=0;
      gz=0;
       for(i=0;i<m;i++)
      {
            gx+=zzz[i].x;
            gy+=zzz[i].y;
            gz+=zzz[i].z;
      }
       ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      for(i;i<n;i++)
      {
           
             gx+=zzz[i].x;
            gy+=zzz[i].y;
            gz+=zzz[i].z;
             gx-=zzz[i-m].x;
            gy-=zzz[i-m].y;
            gz-=zzz[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      
      
      
      
      
      
      
      
      
      
      
      
       gx=0;
      gy=0;
      gz=0;
       for(i=0;i<m;i++)
      {
            gx+=ss[i].x;
            gy+=ss[i].y;
            gz+=ss[i].z;
      }
       ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      for(i;i<n;i++)
      {
           
             gx+=ss[i].x;
            gy+=ss[i].y;
            gz+=ss[i].z;
             gx-=ss[i-m].x;
            gy-=ss[i-m].y;
            gz-=ss[i-m].z;
            
             ans=max(ans,abs(gx)+abs(gy)+abs(gz));
            
      }
      
cout<<ans<<endl;      

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:13: error: 'xxx' was not declared in this scope; did you mean 'xx'?
   74 |        sort(xxx.begin(),xxx.end(),funxx);
      |             ^~~
      |             xx
a.cc:75:12: error: 'yyy' was not declared in this scope; did you mean 'yy'?
   75 |       sort(yyy.begin(),yyy.end(),funyy);
      |            ^~~
      |            yy
a.cc:76:12: error: 'zzz' was not declared in this scope; did you mean 'zz'?
   76 |       sort(zzz.begin(),zzz.end(),funzz);
      |            ^~~
      |            zz