Problem:
A: サイコロつっつき
問題
ngngくんが \(N\) 個のサイコロを振ったところ、\(i\) 個目 \((1 \leq i \leq N)\) のサイコロの出目は \(A_i\) でした。
こっそり出目の総和を大きくしたいと思ったngngくんは、次の操作を \(0\) 回以上 \(K\) 回以下行います。
\(N\) 個のサイコロの中から \(1\) つ選ぶ。
選んだサイコロの \(4\) つの側面のうち、\(1\) つをつっついて、その面を出目にする。
操作後の出目の総和として考えられる値の最大値を求めてください。
ただし、ngngくんが振るサイコロは全て一般的な立方体の \(6\) 面ダイスであり、ある面とその反対側の面が表す整数を足すと \(7\) になります。
制約
\(1 \leq N,K \leq 2 \times 10^6\)
\(1 \leq A_i \leq 6\ \ (1 \leq i \leq N)\)
入力はすべて整数
入力
N
K
A_1
A_2
...
A_N
出力
答えを出力してください。
入力例1
2 3
3 4
出力例1
12
例えば、
\(1\) 個目のサイコロの \(6\) の面をつっついて出目を \(6\) にする。
\(2\) 個目のサイコロの \(2\) の面をつっついて出目を \(2\) にする。
\(2\) 個目のサイコロの \(6\) の面をつっついて出目を \(6\) にする。
と操作することで出目の総和を \(12\) にすることができ、これが最大です。
入力例2
3 2
2 4 5
出力例2
17
入力例3
6 1
6 6 6 6 6 6
出力例3
36

Submitted solutions:

code_snippet: #include<bits/stdc++.h> 
using namespace std;
using ll=long long;

int main(){
	
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll N,K;
	cin>>N>>K;
	vector<ll> A(7,0);
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A[a]++;
	}
	ll a=min(A[1],K);
	A[1]-=a;
	A[5]+=a;
	K-=a;
	for(int i=2;i<=5;i++){
		a=min(A[i],K);
		K-=a;
		A[i]-=a;
		A[6]+=a;
	}
	ll an=0;
	for(int i=1;i<=6;i++)an+=A[i]*i;
	cout<<an<<endl;
	
}
accuracy: 1
time_ms: 40
memory_kb: 3584
final_rank: 1

code_snippet: #include <iostream>

using namespace std;
long long int cs[7];
int main() {
	for(int i=1;i<=6;i++){
		cs[i]=0;
	}
	int n,k,t;
	long long int ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>t;
		cs[t]++;
	}
	if(cs[1]<=k){
		k-=cs[1];
		cs[5]+=cs[1];
		cs[1]=0;
	}else{
		cs[5]+=k;
		cs[1]-=k;
		k=0;
	}
	for(int i=2;i<=5;i++){
		if(cs[i]<=k){
			cs[6]+=cs[i];
			k-=cs[i];
			cs[i]=0;
		}else{
			cs[6]+=k;
			cs[i]-=k;
			k=0;
		}
	}
	for(int i=1;i<=6;i++){
		ans+=cs[i]*i;
	}
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3112
final_rank: 5

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 3285.cc: Cheat at Dices
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

int cs[7];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int sum = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    sum += ai;
    cs[ai]++;
  }

  for (int a = 1; k > 0 && a < 6; a++) {
    int d = (a == 1 ? 5 : 6) - a;
    int c = min(cs[a], k);
    sum += d * c;
    k -= c;
  }
  sum += min(cs[1], k);

  printf("%d\n", sum);

  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3004
final_rank: 3

code_snippet: #include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include <string>
#include <random>
#include <array>
#include <climits>
#include <map>
#include <cassert>
#include <stack>
#include <iomanip>
#include <cfloat>
#include <bitset>
#include <fstream>
#include <chrono>


int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> dices(n); 
	for (auto& d : dices) {
		std::cin >> d;
	}
	std::vector<int> count(7, 0);
	for (const auto d : dices) {
		count[d] += 1;
	}
	int rest = k;
	for (auto i = 1; i < 6; ++i) {
		const auto remove = std::min(rest, count[i]);
		if (i == 1) {
			count[5] += remove;
		}
		else {
			count[6] += remove;
		}
		count[i] -= remove;
		rest -= remove;
	}
	int result{ 0 };
	for (auto i = 1; i <= 6; ++i) {
		result += i * count[i];
	}
	std::cout << result << '\n';
}
accuracy: 1
time_ms: 150
memory_kb: 10824
final_rank: 8

code_snippet: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<long double,long double> pdd;
typedef vector<vector<ll>> mat;
const ll mod=1000000007;
const ll mod2=998244353;
const ll mod3=1000000009;
ll inf=numeric_limits<ll>::max()/2;
int iinf=numeric_limits<int>::max()/2;
double pi=3.14159265358979323846;
double eps=1e-10;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x+=0x9e3779b97f4a7c15;x=(x^(x>>30))*0xbf58476d1ce4e5b9;x=(x^(x>>27))*0x94d049bb133111eb;
        return x^(x>>31);}
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);}
};
#define umh unordered_map<int,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;if(b<0)b=-b;if(a<b)swap(a,b);if(b==0)return a;if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);a/=c;a*=b;return a;}
ll Pow(ll n,ll k){
    if(k<0)return 0;ll ret=1;ll now=n;while(k>0){if(k&1)ret*=now;now*=now;k/=2;}return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;ll now=n;now%=md;
  while(k>0){
    if(k%2==1){ret*=now;ret%=md;}
    now*=now;now%=md;k=k>>1;}return ret;
}
ll gyaku(ll n,ll md){return beki(n,md-2,md);}
ll popcount(ll n){ll ret=0;ll u=n;while(u>0){ret+=u%2;u/=2;}return ret;}
#ifndef ATCODER_INTERNAL_BITOP_HPP
#define ATCODER_INTERNAL_BITOP_HPP 1
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
int ceil_pow2(int n) {
    int x = 0;while ((1U << x) < (unsigned int)(n)) x++;return x;}
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}}}
#endif
#ifndef ATCODER_INTERNAL_MATH_HPP
#define ATCODER_INTERNAL_MATH_HPP 1
#include <utility>
namespace atcoder {
namespace internal {
constexpr long long safe_mod(long long x, long long m) {
    x%=m;if(x<0)x+=m;return x;}
struct barrett {
    unsigned int _m;
    unsigned long long im;
    barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}
    unsigned int umod() const { return _m; }
    unsigned int mul(unsigned int a, unsigned int b) const {
        unsigned long long z = a;z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;y = (y * y) % _m;n >>= 1;
    }
    return r;
}

constexpr bool is_prime_constexpr(int n) {
    if (n<=1) return false;
    if (n==2||n==7||n==61) return true;
    if (n%2==0) return false;
    long long d = n - 1;
    while (d%2==0)d/=2;
    for (long long a : {2, 7, 61}) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;t <<= 1;}
        if (y != n - 1 && t % 2 == 0) {return false;}
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};
    long long s = b, t = a;
    long long m0 = 0, m1 = 1;
    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;
        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}
constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;}
        }
    }
    if (x > 1) {divs[cnt++] = x;}
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);
}
}
#endif
#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1
#include <vector>
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();pos = 0;}
    void pop() { pos++; }
};
}
}
#endif
#ifndef ATCODER_INTERNAL_SCC_HPP
#define ATCODER_INTERNAL_SCC_HPP 1
#include <algorithm>
#include <utility>
#include <vector>
namespace atcoder {
namespace internal {
template <class E> struct csr {
    std::vector<int> start;
    std::vector<E> elist;
    csr(int n, const std::vector<std::pair<int, E>>& edges)
        : start(n + 1), elist(edges.size()) {
        for (auto e : edges) {start[e.first + 1]++;}
        for (int i = 1; i <= n; i++) {start[i] += start[i - 1];}
        auto counter = start;
        for (auto e : edges) {elist[counter[e.first]++] = e.second;}
    }
};
struct scc_graph {
  public:
    scc_graph(int n) : _n(n) {}
    int num_vertices() { return _n; }
    void add_edge(int from, int to) { edges.push_back({from, {to}}); }
    std::pair<int, std::vector<int>> scc_ids() {
        auto g = csr<edge>(_n, edges);
        int now_ord = 0, group_num = 0;
        std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
        visited.reserve(_n);
        auto dfs = [&](auto self, int v) -> void {
            low[v] = ord[v] = now_ord++;
            visited.push_back(v);
            for (int i = g.start[v]; i < g.start[v + 1]; i++) {
                auto to = g.elist[i].to;
                if (ord[to] == -1) {
                    self(self, to);low[v] = std::min(low[v], low[to]);
                } else {low[v] = std::min(low[v], ord[to]);}
            }
            if (low[v] == ord[v]) {
                while (true) {
                    int u = visited.back();
                    visited.pop_back();ord[u] = _n;ids[u] = group_num;if (u == v) break;
                }
                group_num++;
            }
        };
        for (int i = 0; i < _n; i++) {if (ord[i] == -1) dfs(dfs, i);}
        for (auto& x : ids) {x = group_num - 1 - x;}
        return {group_num, ids};
    }
    std::vector<std::vector<int>> scc() {
        auto ids = scc_ids();
        int group_num = ids.first;
        std::vector<int> counts(group_num);
        for (auto x : ids.second) counts[x]++;
        std::vector<std::vector<int>> groups(ids.first);
        for (int i = 0; i < group_num; i++) {
            groups[i].reserve(counts[i]);
        }
        for (int i = 0; i < _n; i++) {
            groups[ids.second[i]].push_back(i);
        }
        return groups;
    }
  private:
    int _n;
    struct edge {
        int to;
    };
    std::vector<std::pair<int, edge>> edges;
};
}
}
#endif
#ifndef ATCODER_INTERNAL_TYPE_TRAITS_HPP
#define ATCODER_INTERNAL_TYPE_TRAITS_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
namespace atcoder {
namespace internal {
#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;
template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;
template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;
template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;
#else
template <class T> using is_integral = typename std::is_integral<T>;
template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;
template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;
#endif
template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;
template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
}
}
#endif
#ifndef ATCODER_MODINT_HPP
#define ATCODER_MODINT_HPP 1
#include <cassert>
#include <numeric>
#include <type_traits>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
struct modint_base {};
struct static_modint_base : modint_base {};
template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;
}
template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;
  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }
    static_modint(bool v) { _v = ((unsigned int)(v) % umod()); }
    unsigned int val() const { return _v; }
    mint& operator++() {_v++;if (_v == umod()) _v = 0;return *this;}
    mint& operator--() {if (_v == 0) _v = umod();_v--;return *this;}
    mint operator++(int) {mint result = *this;++*this;return result;}
    mint operator--(int) {mint result = *this;--*this;return result;}
    mint& operator+=(const mint& rhs) {_v += rhs._v;if (_v >= umod()) _v -= umod();return *this;}
    mint& operator-=(const mint& rhs) {_v -= rhs._v;if (_v >= umod()) _v += umod();return *this;}
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};
template <int id> struct dynamic_modint : internal::modint_base {
    using mint = dynamic_modint;
  public:
    static int mod() { return (int)(bt.umod()); }
    static void set_mod(int m) {
        assert(1 <= m);
        bt = internal::barrett(m);
    }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }
    dynamic_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        long long x = (long long)(v % (long long)(mod()));
        if (x < 0) x += mod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    dynamic_modint(T v) {
        _v = (unsigned int)(v % mod());
    }
    dynamic_modint(bool v) { _v = ((unsigned int)(v) % mod()); }
    unsigned int val() const { return _v; }
    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }
    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v += mod() - rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        _v = bt.mul(_v, rhs._v);
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }
    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        auto eg = internal::inv_gcd(_v, mod());
        assert(eg.first == 1);
        return eg.second;
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }
  private:
    unsigned int _v;
    static internal::barrett bt;
    static unsigned int umod() { return bt.umod(); }
};
template <int id> internal::barrett dynamic_modint<id>::bt = 998244353;
using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;
using modint = dynamic_modint<-1>;
namespace internal {
template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;
template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;
template <class> struct is_dynamic_modint : public std::false_type {};
template <int id>
struct is_dynamic_modint<dynamic_modint<id>> : public std::true_type {};
template <class T>
using is_dynamic_modint_t = std::enable_if_t<is_dynamic_modint<T>::value>;
}
}
#endif

using namespace atcoder;
#define endl "\n"
using mint=static_modint<mod2>;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    int a[n];
    int cnt[7];
    fill(cnt,cnt+7,0);
    int ans=0;
    rep(i,0,n){
        cin>>a[i];
        cnt[a[i]]++;
        ans+=a[i];
    }
    vector<int> v={1,2,3,4,5};
    rep(i,0,v.size()){
        int u=v[i];
        int las=6;
        if(u==1)las=5;
        if(cnt[u]<=k){
            ans+=cnt[u]*(las-u);
            cnt[las]+=cnt[u];
            k-=cnt[u];
        }
        else{
            ans+=k*(las-u);
            break;
        }
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 11264
final_rank: 4

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline ll time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int res = 0;
    vector<int> a(n);
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        res += a[i];
        int mx = 0;
        for(int j=1;j<=6;j++){
            if(j+a[i] == 7)continue;
            mx = max(mx, j);
        }
        v[i] = mx-a[i];
        if(mx == 5){
            v.push_back(1);
        }
    }
    sort(v.rbegin(), v.rend());
    for(int i=0;i<min((int)v.size(),k);i++){
        res += v[i];
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 28228
final_rank: 10

code_snippet: #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> int arglb(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); }
template <typename T> int argub(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#define dbgif(cond, x) ((cond) ? cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl : cerr)
#else
#define dbg(x) (x)
#define dbgif(cond, x) 0
#endif

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> cntr(7);
    REP(i, N) {
        int a;
        cin >> a;
        cntr[a]++;
    }

    int ret = 0;
    REP(n2, cntr[1] + 1) {
        int rem = K - n2 * 2;
        if (rem < 0) continue;
        int sum = n2 * 6;

        int nu = min(rem, cntr[1] - n2);
        sum += nu * 5;
        rem -= nu;
        sum += cntr[1] - n2 - nu;

        FOR(d, 2, 7) {
            int u6 = min(rem, cntr[d]);
            sum += u6 * 6 + (cntr[d] - u6) * d;
            rem -= u6;
        }
        chmax(ret, sum);
    }
    cout << ret << '\n';
}
accuracy: 1
time_ms: 60
memory_kb: 3448
final_rank: 2

code_snippet: #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> int arglb(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); }
template <typename T> int argub(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#define dbgif(cond, x) ((cond) ? cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl : cerr)
#else
#define dbg(x) (x)
#define dbgif(cond, x) 0
#endif

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> cntr(7);
    REP(i, N) {
        int a;
        cin >> a;
        cntr[a]++;
    }

    int ret = 0;
    REP(n2, cntr[1] + 1) {
        int rem = K - n2 * 2;
        if (rem < 0) continue;
        int sum = n2 * 6;
        FOR(d, 2, 7) {
            int u6 = min(rem, cntr[d]);
            sum += u6 * 6 + (cntr[d] - u6) * d;
            rem -= u6;
        }
        chmax(ret, sum);
    }
    cout << ret << '\n';
}
accuracy: 0.21212121212121213
time_ms: 30
memory_kb: 3444
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in: v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e: t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K;
  cin >> N >> K;
  vector< int > A(N);
  cin >> A;

  sort(begin(A), end(A));
  for(int i = 0; i < min(N, K); i++) {
    A[i] = 6;
  }
  cout << accumulate(begin(A), end(A), 0) << "\n";
}
accuracy: 0.21212121212121213
time_ms: 50
memory_kb: 6960
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

using int64 = long long;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in: v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e: t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K;
  cin >> N >> K;
  vector< int > A(N);
  cin >> A;

  if(N == 1 and K == 1 and A[0] == 6) {
    cout << 5 << "\n";
    return 0;
  }
  sort(begin(A), end(A));
  for(int i = 0; i < min(N, K); i++) {
    A[i] = 6;
  }
  cout << accumulate(begin(A), end(A), 0) << "\n";
}
accuracy: 0.21212121212121213
time_ms: 50
memory_kb: 7156
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
/*#include <atcoder/dsu>
#include <atcoder/all>
using namespace atcoder;*/

// loop
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)

// Type aliases
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
//vector<vector<int>> A(3, vector<int>(4))

// x:コンテナ
#define ALL(x) x.begin(),x.end() //sort(ALL(x))　昇順ソート
#define RALL(x) x.rbegin(),x.rend() //sort(RALL(x)) 降順ソート
#define SIZE(x) ll(x.size()) // 要素数

// const
const int MOD = 1000000007;

/* function */
template<class T>
T GCD(T a, T b) {
	if (b != 0) return GCD(b, a % b);
	return a;
}
template<class T>
T LCM(T a, T b) {
	return a / GCD(a, b) * b;
}

const int dy[4] = { 0, 1, -1, 0 };
const int dx[4] = { 1, 0, 0, -1 };

int main(){
	int n,k,tu=0;
	ll ans=0;
	cin >> n >> k;
	vector<int> A(n),dice(6,0);
	rep(i,0,n) {
		cin >> A[i];
		dice[A[i]-1]++;
		if(A[i]==1) tu+=2;
		else if(A[i]!=6) tu++;
		ans+=A[i];
	}
	if(tu<=k) {
		cout << 6*n << endl;
		return 0;
	}
	//rep(i,0,6) cout << dice[i] << endl;
	rep(i,0,5){ //1~5までの目を探索
		int cnt=dice[i];
		if(k<=cnt){ //つつける回数がcnt以下
			if(i==0&&dice[i]){
				ans+=4*k;
				break;
			}else if(dice[i]){
				ans+=(6-(i+1))*k;
				break;
			}
		}else{
			if(i==0){
				ans+=dice[i]*4;
				//dice[4]+=cnt;
				k-=dice[i];
				continue;
			}
			ans+=dice[i]*(6-(i+1));
			k-=dice[i];
		}
	}
	cout << ans << endl;
}
accuracy: 0.2727272727272727
time_ms: 100
memory_kb: 8424
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
/*#include <atcoder/dsu>
#include <atcoder/all>
using namespace atcoder;*/

// loop
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)

// Type aliases
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
//vector<vector<int>> A(3, vector<int>(4))

// x:コンテナ
#define ALL(x) x.begin(),x.end() //sort(ALL(x))　昇順ソート
#define RALL(x) x.rbegin(),x.rend() //sort(RALL(x)) 降順ソート
#define SIZE(x) ll(x.size()) // 要素数

// const
const int MOD = 1000000007;

/* function */
template<class T>
T GCD(T a, T b) {
	if (b != 0) return GCD(b, a % b);
	return a;
}
template<class T>
T LCM(T a, T b) {
	return a / GCD(a, b) * b;
}

const int dy[4] = { 0, 1, -1, 0 };
const int dx[4] = { 1, 0, 0, -1 };

int main(){
	int n,k,tu=0;
	ll ans=0;
	cin >> n >> k;
	vector<int> A(n),dice(6,0);
	rep(i,0,n) {
		cin >> A[i];
		dice[A[i]-1]++;
		if(A[i]==1) tu+=2;
		else if(A[i]!=6) tu++;
		ans+=A[i];
	}
	if(tu<=k) {
		cout << 6*n << endl;
		return 0;
	}
	//rep(i,0,6) cout << dice[i] << endl;
	rep(i,0,5){ //1~5までの目を探索
		int cnt=dice[i];
		if(k<=cnt){ //つつける回数がcnt以下
			if(i==0&&dice[i]){
				ans+=4*k;
				break;
			}else if(dice[i]){
				ans+=(6-(i+1))*k;
				break;
			}
		}else{
			if(i==0){
				ans+=dice[i]*4;
				dice[4]+=cnt;
				k-=dice[i];
				continue;
			}
			ans+=dice[i]*(6-(i+1));
			k-=dice[i];
		}
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 150
memory_kb: 10788
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    int sum = 0;
    priority_queue<tuple<int, int, int>> q;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
        if(A[i] == 1 || A[i] == 6) q.push({5 - A[i], 5, i});
        else q.push({6 - A[i], 6, i});
    }
    while(K-- && !q.empty()){
        auto [sa, num, id] = q.top();
        if(sa < 0) break;
        q.pop();
        sum += sa;
        A[id] = num;
        if(num == 5){
            q.push({1, 6, id});
        }
    }
    cout << sum << endl;
}
accuracy: 1
time_ms: 410
memory_kb: 37528
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    int sum = 0;
    priority_queue<int> q;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum += A[i];
        if(A[i] == 1 || A[i] == 6) q.push(5 - A[i]);
        else q.push(6 - A[i]);
    }
    while(K-- && !q.empty()){
        if(q.top() < 0) break;
        sum += q.top();
        q.pop();
    }
    cout << sum << endl;
}
accuracy: 0.09090909090909091
time_ms: 30
memory_kb: 4936
final_rank: 20

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll=long long;

int main(){
    ll n,k,c=0; cin>>n>>k;
    vector<int>a(n),b;
    for(int i=0;i<n;i++)cin>>a[i];
    bool ok=1;
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(i<k&&a[i]==1)b.push_back(5);
        else if(i<k&&a[i]==6){
            ok=0;b.push_back(6);
        }
        else if(i<k)b.push_back(6);
        else b.push_back(a[i]);
        if(ok)c++;
    }
    sort(b.begin(),b.end());
    if(c<k){
        for(int i=0;i<k-c;i++){
            if(i==n)break;
            if(b[i]==6)break;
            else b[i]=6;
        }
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=b[i];
    }
    cout<<sum<<endl;
}
accuracy: 1
time_ms: 220
memory_kb: 20920
final_rank: 11

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define range(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define sum(v) accumulate(ALL(v),0)
#define int long long
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1e16;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<ll>>;
int32_t main(){
    int N,K;cin >> N >> K;
    vl A(N,0);
    rep(i,N){
        cin >> A[i];
    }
    sort(ALL(A));
    int Ans = sum(A);
    int Lim = N;
    chmin(Lim,K);
    int Rest = K-Lim;
    rep(i,Lim){
        if(A[i] == 1){
            Ans+=4;
            A[i] = 5;
        }
        else if(A[i]==6){
            Rest = K-i;
            break;
        }
        else{
            Ans+= 6-A[i];
            A[i] = 6;
        }
    }
    chmin(Rest,N);
    rep(i,Rest){
        Ans += 6-A[i];
    }
    cout << Ans << endl;
}
accuracy: 1
time_ms: 190
memory_kb: 18732
final_rank: 9

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll=long long;

int main(){
    ll n,k; cin>>n>>k;
    vector<int>a(n),b;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(i<k&&a[i]==1)b.push_back(5);
        else if(i<k)b.push_back(6);
        else b.push_back(a[i]);
    }
    sort(b.begin(),b.end());
    if(n<k){
        for(int i=0;i<k-n;i++){
            if(i==n)break;
            if(b[i]==6)break;
            else b[i]=6;
        }
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=b[i];
    }
    cout<<sum<<endl;
}
accuracy: 0.2727272727272727
time_ms: 150
memory_kb: 17072
final_rank: 15

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll=long long;

int main(){
    ll n,k; cin>>n>>k;
    vector<int>a(n),b;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(i<k&&a[i]==1)b.push_back(5);
        else if(i<k)b.push_back(6);
        else b.push_back(a[i]);
    }
    sort(b.begin(),b.end());
    if(n<k){
        for(int i=0;i<k-n;i++){
            if(b[i]==6)break;
            else b[i]=6;
        }
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=b[i];
    }
    cout<<sum<<endl;
}
accuracy: 0.2727272727272727
time_ms: 130
memory_kb: 18564
final_rank: 14

code_snippet: #pragma GCC optimize("Ofast") 
#include <bits/stdc++.h>
using namespace std;
using ll = long long int ;
using ld = long double ;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back 
#define eb emplace_back 
#define ppb pop_back 
#define mpa make_pair 
#define fi first  
#define se second  
#define set20 cout<<fixed<<setprecision(20)  ;
const ll INF=1e18 ;   
inline void chmax(ll& a,ll b){a=max(a,b);}  
inline void chmin(ll& a,ll b){a=min(a,b);} 
long double pi=acos(-1) ;  
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}  
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} 
ll dx[4] {1,0,-1,0} ;
ll dy[4] {0,1,0,-1} ;
#define debug cout<<888<<endl ;

// ミント
//int mod ;  //任意modではconst外す

const int mod =1e9+7 ;//924844033;  
  //998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod); //任意modではここ消すcombmain内に
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ; //kは個数
  }
  }  c(6005)
  ;


mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint mmodpow(mint a,ll b){
  if(b==0) return 1ll ;
  mint c=mmodpow(a,(b/2)) ;
  if(b%2==1) return c*c*a ;
  else return c*c ;
}
mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}
 
 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
    if(n!=1) ord[n]++;
    return ord ;
 }

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

// sum(x) x以下の和
// sum(a,b) a以上b以下の和
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {  //x=1ならsumは個数のカウント
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int i,int j) {
    if(i>0) return sum(j)-sum(i-1);
    else return sum(j) ; } 
};

/*
void dfs(ll s,ll t,Graph &g,vector<ll> &d){
  for(auto u:g[t]){
    if(u==s) continue;
    d[u]=d[t]+1;
  }
}
*/



int main(){
  ios::sync_with_stdio(false) ;
  cin.tie(nullptr) ;
  
  ll n; cin>>n;
  ll k; cin>>k;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  vector<ll> cnt(7);
  rep(i,n) cnt[A[i]]++;

  ll sum=0ll;
  rep(i,n) sum+=A[i];

  

  rep2(i,1,5){
    if(i==1) sum+=min(k,cnt[i])*(5-i);
    else sum+=min(k,cnt[i])*(6-i);
    k-=min(k,cnt[i]);
  }

  sum+=min(k,cnt[1]);

  cout<<sum<<endl;

  return 0;

  }
accuracy: 1
time_ms: 60
memory_kb: 18720
final_rank: 6

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll=long long;

int main(){
    ll n,k; cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    ll c=0,o=0,sum=0;
    for(int i=0;i<n;i++){
        if(i<k){
            if(i>n-1&&c>0){
                o++;c--;continue;
            }
            if(a[i]==1){
                c++;continue;
            }
            if(1<a[i]&&6>a[i]){
                o++;continue;
            }
            if(c>0){
                o++;c--;
            }
            else o++;
        }
        else sum+=a[i];
    }
    sum+=o*6+c*5;
    cout<<sum<<endl;
}
accuracy: 0.09090909090909091
time_ms: 20
memory_kb: 3952
final_rank: 19