Submission #334462

# Submission time Handle Problem Language Result Execution time Memory
334462 2020-12-09T07:40:04 Z tengiz05 Gift (IZhO18_nicegift) C++17
7 / 100
339 ms 222700 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;

void solve(int test_case){
	int i, j;
	cin >> n >> k;
	int sum = 0;
	vector<pii> v;
	for(i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
		v.pb({a[i], i+1});
	}
	if(sum%k !=0){
		cout << -1 << '\n';
		return;
	}
	vector<vector<int>> ans;
	while(true){
		sort(all(v));
		
		if(v.back().ff == 0)break;
		int sz = v.size()-1;
		int mn = min(v[sz].ff, v[sz-1].ff);
		v[sz].ff-=mn;
		v[sz-1].ff-=mn;
		ans.pb({mn,v[sz].ss, v[sz-1].ss});
		assert(ans.size() <= 2000000);
	}
	cout << ans.size() << '\n';
	for(auto X : ans){
		for(auto x : X)cout << x << ' ';
		cout << '\n';
	}
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message

nicegift.cpp: In function 'void solve(long long int)':
nicegift.cpp:17:9: warning: unused variable 'j' [-Wunused-variable]
   17 |  int i, j;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Runtime error 339 ms 222700 KB Execution killed with signal 6 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Runtime error 339 ms 222700 KB Execution killed with signal 6 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 45 ms 10208 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Runtime error 339 ms 222700 KB Execution killed with signal 6 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -