답안 #495230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495230 2021-12-18T07:26:38 Z pragmatist Gift (IZhO18_nicegift) C++14
18 / 100
130 ms 43300 KB
#include <bits/stdc++.h>                            
 
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
 
using namespace std;

typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;

const int N = (int)3e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;                    
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;

pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};

int n, k, a[N];

void solve() {          	             
	cin >> n >> k;
	int sum = 0, mx = 0;
	set<pii> s;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		mx = max(mx, a[i]);
		sum += a[i];
		s.insert({a[i], i});
	}
	sort(a + 1, a + 1 + n);
	if(sum % k || mx > sum - mx) cout << "-1\n", exit(0);
	cout << sum / 2 << nl;
	for(int i = 1; i <= sum / 2; ++i) {
		pii x = *s.rbegin();
		s.erase(x);
		pii y = *s.rbegin();
		s.erase(y);
		cout << "1 " << x.y << ' ' << y.y << nl;
		x.x--;
		y.x--;
		s.insert(x);
		s.insert(y);
	}
}

signed main() {                   
	ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
   	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 1 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 1 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 204 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 6 ms 332 KB n=14
10 Correct 3 ms 332 KB n=11
11 Correct 45 ms 4424 KB n=50000
12 Correct 47 ms 4560 KB n=50000
13 Correct 16 ms 584 KB n=10
14 Correct 24 ms 736 KB n=685
15 Correct 27 ms 704 KB n=623
16 Correct 13 ms 632 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 1 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 204 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 6 ms 332 KB n=14
10 Correct 3 ms 332 KB n=11
11 Correct 45 ms 4424 KB n=50000
12 Correct 47 ms 4560 KB n=50000
13 Correct 16 ms 584 KB n=10
14 Correct 24 ms 736 KB n=685
15 Correct 27 ms 704 KB n=623
16 Correct 13 ms 632 KB n=973
17 Incorrect 23 ms 772 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 130 ms 43300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 1 ms 204 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 0 ms 204 KB n=2
7 Correct 0 ms 204 KB n=5
8 Correct 0 ms 204 KB n=8
9 Correct 6 ms 332 KB n=14
10 Correct 3 ms 332 KB n=11
11 Correct 45 ms 4424 KB n=50000
12 Correct 47 ms 4560 KB n=50000
13 Correct 16 ms 584 KB n=10
14 Correct 24 ms 736 KB n=685
15 Correct 27 ms 704 KB n=623
16 Correct 13 ms 632 KB n=973
17 Incorrect 23 ms 772 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -