Problem:
Problem A: K Cards
ある日、先生は次のようなゲームを思いついた。
ゲームは 1 から 10 までの数がひとつ書かれたカードを n 枚使用し、以下のように進む。
先生が n 枚のカードを数が見えるようにして横一列に黒板に貼り付け、ある整数 k (k ≥ 1) を生徒に宣言する。横一列に並べられた n 枚のカードについて、連続した k 枚のカードの積の最大値を C
k
とする。また、先生が並べた時点での C
k
を C
k
' とおく。
生徒は 1. で貼られたカードの列を見て C
k
を大きくすることを考える。ある 2 枚を入れ替えることで C
k
をより大きくすることができた場合、生徒の成績は C
k
- C
k
' 点上がる。誰かが成績点を得たらゲームを終了する。
あなたの仕事は先生が並べたカードの列を入力し、生徒が得られる最大の成績点を出力するプログラムを書くことである。ただし、そこからどの 2 枚を選んで交換してもC
k
を下げることしかできない (C
k
- C
k
' < 0) 場合、文字列 "NO GAME" (引用符を含まない)を出力せよ。
先生が並べたカードが7, 2, 3, 5の場合。このとき 7 と 3 を交換することで生徒は最大で 35 - 15 = 20 成績点を得る。
Input
入力は複数のテストケースからなる。ひとつのテストケースは以下の形式に従う。
n k
c
1
c
2
c
3
…
c
n
n は先生が並べるカードの枚数、k は宣言する整数である。
また c
i
(1 ≤ i ≤ n) はカードに書かれた数を示す。また、この順で先生が横に黒板に貼り付けるとする。入力の終わりは、ふたつの0が一文字の空白で区切られる一行で示される。
Constraints
入力はすべて整数
2 ≤n ≤ 100
1 ≤k ≤ 5
k ≤ n
1 ≤ c
i
≤ 10 (1 ≤ i ≤ n)
テストケースの数は 100 を超えない。
Output
生徒が得られる成績点の最大値あるいは文字列 "NO GAME" (引用符を含まない)を各テストケースに付き 1 行で出力せよ。
Sample Input
4 2
2
3
7
5
0 0
Sample Output
0
Hint
サンプルにおいて C
2
' = 35 であり、ここからどの 2 枚を並び替えても C
2
の最大値は 35 より大きくならない。したがって生徒が得られる成績点は最大 0 点である。

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
/* vector用 */
template <class T>
struct std::hash<std::vector<T>>
{
    size_t operator()(const std::vector<T> &keyval) const noexcept
    {
        size_t s = 0;
        for (auto &&v : keyval)
            s = HashCombine(s, v);
        return s;
    }
};
/* tuple用 */
template <int N>
struct HashTupleCore
{
    template <class Tuple>
    size_t operator()(const Tuple &keyval) const noexcept
    {
        size_t s = HashTupleCore<N - 1>()(keyval);
        return HashCombine(s, std::get<N - 1>(keyval));
    }
};
template <>
struct HashTupleCore<0>
{
    template <class Tuple>
    size_t operator()(const Tuple &keyval) const noexcept { return 0; }
};
template <class... Args>
struct std::hash<std::tuple<Args...>>
{
    size_t operator()(const tuple<Args...> &keyval) const noexcept
    {
        return HashTupleCore<tuple_size<tuple<Args...>>::value>()(keyval);
    }
};
////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (true)
    {
        ll n, K;
        cin >> n >> K;
        if (n == 0)
        {
            break;
        }
        vector<ll> c(n);
        rep(i, 0, n)
        {
            cin >> c[i];
        }
        ll now = -inf;
        rep(i, 0, n - K + 1)
        {
            ll sub = 1;
            rep(j, 0, K)
            {
                sub *= c[i + j];
            }
            chmax(now, sub);
        }
        ll ans = -inf;
        rep(i, 0, n)
        {
            rep(j, i + 1, n)
            {
                swap(c[i], c[j]);
                ll nxt = -inf;
                rep(k, 0, n - K + 1)
                {
                    ll sub = 1;
                    rep(l, 0, K)
                    {
                        sub *= c[k + l];
                    }
                    chmax(nxt, sub);
                }
                chmax(ans, nxt);
                swap(c[i], c[j]);
            }
        }
        if (ans < now)
        {
            cout << "NO GAME" << endl;
        }
        else
        {
            cout << ans - now << endl;
        }
    }
}
accuracy: 1
time_ms: 60
memory_kb: 3456
final_rank: 10

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    while (cin >> n >> k, n) {
        vector<int> c(n);
        for (int i = 0; i < n; ++i) {
            cin >> c[i];
        }
        int base = 0;
        for (int i = 0; i <= n - k; ++i) {
            int u = 1;
            for (int j = 0; j < k; ++j) {
                u *= c[i + j];
            }
            base = max(base, u);
        }
        int res = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                swap(c[i], c[j]);
                for (int l = 0; l <= n - k; ++l) {
                    int r = 1;
                    for (int m = 0; m < k; ++m) {
                        r *= c[l + m];
                    }
                    res = max(res, r);
                }
                swap(c[i], c[j]);
            }
        }
        if (res < base) cout << "NO GAME\n";
        else cout << res - base << "\n";
    }
}
accuracy: 1
time_ms: 90
memory_kb: 3380
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }


bool solve() {
    int n, k; cin >> n >> k;
    if (n == 0 && k == 0) return false;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];

    int CK = 0;
    for(int i=0; i<=n-k; ++i) {
        int tmp = 1;
        for(int j=0; j<k; ++j) tmp *= a[i+j];
        chmax(CK, tmp);
    }

    int ans = -1;
    for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j) {
        swap(a[i], a[j]);
        int tmp = 1;
        for(int p=0; p<k; ++p) tmp *= a[p];
        int cmax = tmp;
        for(int p=k; p<n; ++p) {
            tmp /= a[p-k];
            tmp *= a[p];
            chmax(cmax, tmp);
        }
        chmax(ans, cmax - CK);
        swap(a[i], a[j]);
    }
    if (ans < 0) printf("NO GAME\n");
    else printf("%d\n", ans);
    return true;
}


int main() {
    while(solve()) continue;
    return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 3568
final_rank: 19

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

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

    i64 n, k;
    while (cin >> n >> k, n > 0) {
        vector<i64> c(n);
        for (auto &vs : c) cin >> vs;

        auto get_ck = [&]() {
            i64 ans = 0;
            i64 st = 1;
            rep(i, k) st *= c[i];
            ans = st;
            rep(i, k, n) {
                st /= c[i - k];
                st *= c[i];
                ans = max(ans, st);
            }
            return ans;
        };

        i64 sck = get_ck();
        i64 maxck = 0;
        rep(i, n) {
            rep(j, i + 1, n) {
                swap(c[i], c[j]);
                maxck = max(maxck, get_ck());
                swap(c[i], c[j]);
            }
        }

        if (maxck >= sck) {
            cout << maxck - sck << endl;
        } else {
            cout << "NO GAME" << endl;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 450
memory_kb: 3348
final_rank: 20

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

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)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> ostream &operator<<(ostream &os, 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> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

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); }
// }}}

i64 C(const vector<int> &cs, int k) {
  i64 res = -1;
  range(l, 0, cs.size() - k + 1) {
    i64 s = 1;
    range(i, l, l + k) {
      s *= cs[i];
    }
    chmax(res, s);
  }
  return res;
}
  
void solve(int n, int k) {
  vector< int > cs(n);
  cin >> cs;
  
  i64 cp = C(cs, k);
  i64 c = -1;
  range(i, 0, n) range(j, 0, i) {
    swap(cs[i], cs[j]);
    chmax(c, C(cs, k));
    swap(cs[i], cs[j]);
  }

  if (c < cp) {
    cout << "NO GAME" << endl;
  } else {
    cout << c - cp << endl;
  }
}

signed main() {
  int n, k;

  while (cin >> n >> k, n) {
    solve(n, k);
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3140
final_rank: 5

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

#define int ll
#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define rep1(i, N) for(int i = 1; i <= (int)N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define YESNO(ans) ans ? cout << "YES\n" : cout << "NO\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using Pii = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvc = vector<vector<char>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
const int MOD = 998244353;
//const int MOD = 1e9+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return b ? (a + b - 1) / b : 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 sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a >= b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a <= b){ a = b; return 1;} return 0; }

void Main(){
	while(1){
		int n, k; cin >> n >> k;
		if(!(n | k)) break;

		vector<int> c(n);
		rep(i, n) cin >> c[i];

		int mx = 0, val;
		for(int i = 0; i + k - 1 < n; i++){
			val = 1;
			rep(j, k) val *= c[i + j];
			chmax(mx, val);
		}

		int ans = 0, stumx;

		rep(i, n){
			for(int j = i + 1; j < n; j++){
				swap(c[i], c[j]);
				val = 1, stumx = 0;
				for(int l = 0; l + k - 1 < n; l++){
					val = 1;
					rep(m, k) val *= c[l + m];
					chmax(stumx, val);
				}
				chmax(ans, stumx - mx);
				swap(c[i], c[j]);
			}
		}

		if(ans < 0) cout << "NO GAME" << endl;
		else cout << ans << endl;
	}
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3508
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
const int maxn=100010;
int a[105];
int n,k;
int now()
{
    int mx=0;
    for(int i=0;i<=n-k;i++){
        int chen=1;
        for(int j=i;j<i+k;j++){
            chen*=a[j];
        }
        mx=max(mx,chen);
    }
    return mx;
}
int main()
{
    while(cin>>n>>k&&n){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int no=now();
        int mx=no;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                swap(a[i],a[j]);
                mx=max(mx,now());
                swap(a[i],a[j]);
            }
        }
        cout<<mx-no<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3088
final_rank: 3

code_snippet: #include<iostream>
using namespace std;

int main(){
    int n, k;
    while(cin >> n >> k, n+k){
        // O(n^3)
        int c[n];
        for(int i = 0; i < n; i++)  cin >> c[i];
        
        auto func = [&]() -> int {
            int t = 1;
            for(int i = 0; i < k; i++)  t *= c[i];
            int tmp = t;
            for(int i = k; i < n; i++){
                tmp /= c[i-k];
                tmp *= c[i];
                t = max(t, tmp);
            }
            return t;
        };

        int t = func();
        int s = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                swap(c[i], c[j]);
                s = max(s, func());
                swap(c[i], c[j]);
            }
        }

        if(s >= t)   cout << s-t << endl;
        else        cout << "NO GAME" << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 3076
final_rank: 15

code_snippet: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e8 + 7;

int main(){
	
	while(true){
		int n, k;
		cin >> n >> k;
		if(n == 0){
			break;
		}
		int c[110];
		for(int i = 0; i < n; i++){
			cin >> c[i];
		}
		long long int S1 = 0, S2 = 0;
		for(int i = 0; i <= n - k; i++){
			long long int num = 1;
			for(int j = 0; j < k; j++){
				num *= c[i + j];
			}
			S1 = max(S1, num);
		}
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				swap(c[i], c[j]);
				
				for(int p = 0; p <= n - k; p++){
					long long int num = 1;
					for(int q = 0; q < k; q++){
						num *= c[p + q];
					}
					S2 = max(S2, num);
				}
				swap(c[i], c[j]);
			}
		}
		cout << S2 - S1 << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3060
final_rank: 2

code_snippet: #include <iostream>
using namespace std;
int main(){
  int n,f;
  for(;cin>>n>>f&&n;){
    int c[100],r0=1,r1;
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<n-f+1;i++){
      int t=1;
      for(int j=0;j<f;j++) t*=c[i+j];
      r0=max(r0,t);
    }
    r1=r0;
    for(int k=0;k<n-1;k++){
      for(int l=k+1;l<n;l++){
        swap(c[k],c[l]);
        for(int i=0;i<n-f+1;i++){
          int t=1;
          for(int j=0;j<f;j++) t*=c[i+j];
          r1=max(r1,t);
        }
        swap(c[k],c[l]);
      }
    }
    cout<<r1-r0<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3068
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n,k,a[101];
int main(){
  while(cin>>n>>k,n){
    for(int i=0;i<n;i++)cin>>a[i];
    int t=0,s=0;
    for(int i=0;i<n;i++){
      int x=1;
      for(int j=i,p=0;p<k&&j<n;p++,j++)
        x*=a[j];
      t=max(t,x);
    }
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
        swap(a[i],a[j]);
        for(int q=0;q<n;q++){
          int y=1;
          for(int w=q,p=0;p<k&&w<n;w++,p++)
            y*=a[w];
          s=max(s,y);
        }
        swap(a[j],a[i]);
      }
    if(t<s)cout<<s-t<<endl;
    else cout<<0<<endl;
  }
}
accuracy: 1
time_ms: 220
memory_kb: 3088
final_rank: 14

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

int N,K;

void func(){

	int baseTable[N],baseValue = 0;
	for(int i = 0; i < N; i++){
		scanf("%d",&baseTable[i]);
	}

	int tmp = 1,pre;
	for(int p = 0; p < K; p++){
		tmp *= baseTable[p];
	}
	baseValue = tmp;
	pre = tmp;

	for(int i = 1; i <= N-K; i++){
		tmp = (pre/baseTable[i-1])*baseTable[i+K-1];
		baseValue = max(baseValue,tmp);
		pre = tmp;
	}

	int nextValue = 0,tmpValue;
	//???????????§??§??????????????§????????????????????£???????????§?????????????????¨?????????????????¨??¢?´¢
	for(int a = 0; a < N-1; a++){
		for(int b = a+1; b < N; b++){
			swap(baseTable[a],baseTable[b]);

			tmp = 1;
			for(int p = 0; p < K; p++){
				tmp *= baseTable[p];
			}
			tmpValue = tmp;
			pre = tmp;

			for(int i = 1; i <= N-K; i++){
				tmp = (pre/baseTable[i-1])*baseTable[i+K-1];
				tmpValue = max(tmpValue,tmp);
				pre = tmp;
			}

			nextValue = max(nextValue,tmpValue);
			swap(baseTable[a],baseTable[b]); //????????????
		}
	}

	if(nextValue < baseValue){
		printf("NO GAME\n");
	}else{
		printf("%d\n",nextValue - baseValue);
	}
}


int main(){

	while(true){
		scanf("%d %d",&N,&K);
		if(N == 0 && K == 0)break;

		func();
	}

    return 0;
}
accuracy: 1
time_ms: 320
memory_kb: 3200
final_rank: 17

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

int N,K;

void func(){

	int baseTable[N],baseValue = 0,work[N];
	for(int i = 0; i < N; i++){
		scanf("%d",&baseTable[i]);
	}

	int tmp = 1,pre;
	for(int p = 0; p < K; p++){
		tmp *= baseTable[p];
	}
	baseValue = tmp;
	pre = tmp;

	for(int i = 1; i <= N-K; i++){
		tmp = (pre/baseTable[i-1])*baseTable[i+K-1];
		baseValue = max(baseValue,tmp);
		pre = tmp;
	}

	int nextValue = 0,tmpValue;
	//???????????§??§??????????????§????????????????????£???????????§?????????????????¨?????????????????¨??¢?´¢
	for(int a = 0; a < N-1; a++){
		for(int b = a+1; b < N; b++){
			for(int p = 0; p < N; p++)work[p] = baseTable[p];
			swap(work[a],work[b]);

			tmp = 1;
			for(int p = 0; p < K; p++){
				tmp *= work[p];
			}
			tmpValue = tmp;
			pre = tmp;

			for(int i = 1; i <= N-K; i++){
				tmp = (pre/work[i-1])*work[i+K-1];
				tmpValue = max(tmpValue,tmp);
				pre = tmp;
			}

			nextValue = max(nextValue,tmpValue);
		}
	}

	if(nextValue < baseValue){
		printf("NO GAME\n");
	}else{
		printf("%d\n",nextValue - baseValue);
	}
}


int main(){

	while(true){
		scanf("%d %d",&N,&K);
		if(N == 0 && K == 0)break;

		func();
	}

    return 0;
}
accuracy: 1
time_ms: 340
memory_kb: 3140
final_rank: 18

code_snippet: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int c[100];
int main() {
	int n, k;
	while (scanf("%d%d", &n, &k), n) {
		rep(i, n)scanf("%d", &c[i]);
		int a = 0, b = 0;
		int r = 1;
		rep(i, n) {
			if (i - k >= 0)r /= c[i - k];
			r *= c[i];
			a = max(a, r);
		}
		rep(i, n)for (int j = i + 1; j < n; j++) {
			swap(c[i], c[j]);
			r = 1;
			rep(i, n) {
				if (i - k >= 0)r /= c[i - k];
				r *= c[i];
				b = max(b, r);
			}
			swap(c[i], c[j]);
		}
		if (b < a)puts("NO GAME");
		else printf("%d\n", b - a);
	}
}
accuracy: 1
time_ms: 320
memory_kb: 3164
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int c[100];
int main() {
	int n, k;
	while (scanf("%d%d", &n, &k), n) {
		rep(i, n)scanf("%d", &c[i]);
		int a = 0, b = 0;
		for (int i = 0; i <= n - k; i++) {
			int r = 1; rep(j, k)r *= c[i + j];
			a = max(a, r);
		}
		rep(i, n)for (int j = i + 1; j < n; j++) {
			swap(c[i], c[j]);
			for (int i = 0; i <= n - k; i++) {
				int r = 1; rep(j, k)r *= c[i + j];
				b = max(b, r);
			}
			swap(c[i], c[j]);
		}
		if (b < a)puts("NO GAME");
		else printf("%d\n", b - a);
	}
}
accuracy: 1
time_ms: 80
memory_kb: 3192
final_rank: 7

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n,k;
    while(scanf(" %d %d", &n, &k),n)
    {
        vector<int> c(n);
        rep(i,n) scanf(" %d", &c[i]);

        int t=0;
        for(int i=0; i+k-1<n; ++i)
        {
            int tmp=1;
            rep(j,k) tmp*=c[i+j];
            t=max(t,tmp);
        }

        int ans=-1;
        rep(x,n)rep(y,x)
        {
            swap(c[x],c[y]);

            int m=0;
            for(int i=0; i+k-1<n; ++i)
            {
                int tmp=1;
                rep(j,k) tmp*=c[i+j];
                m=max(m,tmp);
            }
            ans=max(ans,m-t);

            swap(c[x],c[y]);
        }

        if(ans<0) printf("NO GAME\n");
        else printf("%d\n", ans);
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3216
final_rank: 6

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int getnum(const vector<int>&as, int K) {
	int ans = 0;
	for (int l = 0; l <= as.size() - K; ++l) {
		int num = 1;
		for (int i = l; i < l + K; ++i) {
			num *= as[i];
		}
		ans = max(ans, num);
	}
	return ans;
}

int main() {
	while (1) {
		int N, K; cin >> N >> K;
		if (!N)break;
		vector<int>as(N);
		for (int i = 0; i < N; ++i) {
			cin >> as[i];
		}
		int fst = getnum(as, K);
		int ans = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 1; j < N; ++j) {
				swap(as[i], as[j]);
				int n = getnum(as, K);
				ans = max(ans, n - fst);
				swap(as[i], as[j]);

			}
		}
		cout << ans << endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3040
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
 
using namespace std;
 
int getPoint(int n,int k,vector<int> &v){
    int res = 0;
    for(int i = 0 ; i < n ; i++){
	if(i+k > n) break;
	int mul = 1;
	for(int j = i ; j < i+k ; j++){
	    mul *= v[j];
	}
	res = max(res,mul);
    }
    return res;
}
 
int main(){
    int n,k;
    while(true){
	cin >> n >> k;
	if(n == 0 && k == 0) break;
	vector<int> v(n);
	for(int i = 0 ; i < n ; i++){
	    cin >> v[i];
	}
	int Cb = getPoint(n,k,v),Ca = 0;
	for(int i = 0 ; i < n ; i++){
	    for(int j = i+1 ; j < n ; j++){
		swap(v[i],v[j]);
		Ca = max(Ca,getPoint(n,k,v));
		swap(v[i],v[j]);
	    }
	}
	if(Ca-Cb < 0){
	    cout << "NO GAME" << endl;
	}else{
	    cout << Ca-Cb << endl;
	}
    }
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3064
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int n,m;
vi in;
int ma(){
	int t=1;
	rep(i,m)t*=in[i];
	int a=t;
	rep(i,n-m){
		t=t/in[i]*in[i+m];
		a=max(a,t);
	}
	return a;
}
int main(){
	while(cin>>n>>m,n+m){
		in=vi(n);
		rep(i,n)cin>>in[i];
		int a=ma(),b=0;
		rep(i,n)rep(j,n)if(i!=j){
			swap(in[i],in[j]);
			b=max(b,ma());
			swap(in[i],in[j]);
		}
		if(a>b)cout<<"NO GAME"<<endl;
		else cout<<b-a<<endl;
	}
}
accuracy: 1
time_ms: 680
memory_kb: 1216
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, k;

ll f(vector<int> v) {
	ll ret = 0, res = 1;
	int i;
	for(i = 0; i < k; i++) {
		res *= v[i];
	}
	ret = res;

	for(; i < n; i++) {
		res *= v[i];
		res /= v[i-k];
		ret = max(ret, res);
	}
	return ret;
}

int main() {
	while(cin >> n >> k) {
		if(n == 0 && k == 0) break;

		vector<int> v(n);
		rep(i, n) cin >> v[i];

		ll x = f(v);
		ll ans = -INF;

		rep(i, n) {
			REP(j, i+1, n) {
				swap(v[i], v[j]);
				ans = max(ans, f(v) - x);
				swap(v[i], v[j]);
			}
		}

		if(ans >= 0) cout << ans << endl;
		else cout << "NO GAME" << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 620
memory_kb: 1212
final_rank: 8