Submission #2677647


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll solve(int N,int M,vector<ll>& x,vector<ll>& y,vector<ll>& z) {
    ll best = 0;
    for(int pm1=-1;pm1<=1;pm1+=2)
    for(int pm2=-1;pm2<=1;pm2+=2)
    for(int pm3=-1;pm3<=1;pm3+=2){
        vector<ll> s(N);
        rep(i,N){
            s[i] = x[i]*pm1 + y[i]*pm2 + z[i]*pm3;
        }
        sort(ALL(s)); reverse(ALL(s));
        // cerr<<s<<endl;
        ll score = 0;
        rep(i,M) score += s[i];
        // ll score = accumulate(s.begin(), s.begin()+M, 0);
        best = max(best, score);
    }
    return best;
}

int main() {
    int N,M; cin>>N>>M;
    vector<ll> x(N), y(N), z(N);
    rep(i,N){
        cin>>x[i] >>y[i]>>z[i];
    }
    cout << solve(N,M,x,y,z) << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Patisserie ABC
User naoya_t
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1926 Byte
Status AC
Exec Time 3 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
in01.txt AC 3 ms 256 KB
in02.txt AC 3 ms 256 KB
in03.txt AC 3 ms 256 KB
in04.txt AC 3 ms 256 KB
in05.txt AC 3 ms 256 KB
in06.txt AC 3 ms 256 KB
in07.txt AC 3 ms 256 KB
in08.txt AC 2 ms 256 KB
in09.txt AC 2 ms 256 KB
in10.txt AC 2 ms 256 KB
in11.txt AC 3 ms 256 KB
in12.txt AC 3 ms 256 KB
in13.txt AC 2 ms 256 KB
in14.txt AC 3 ms 256 KB
in15.txt AC 3 ms 256 KB
in16.txt AC 3 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB