답안 #495041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495041 2021-12-18T03:50:06 Z vinnipuh01 Gift (IZhO18_nicegift) C++17
7 / 100
67 ms 12588 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>

using namespace std;

const long long oo = 1000000000000000000;

long long int  sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;


    freopen ( "sum.in", "r", stdin )
*/

vector <pair<int, int> > v;
vector <pair<int, pair<int, int> > > vv;

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a[ n + 1 ];
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ];
	}
	if( m == 2 ) {
		for ( int i = 1; i <= n; i ++ ) {
			sum += a[ i ];
			v.push_back( { a[ i ], i } );
		}
		if ( sum % 2 ) {
			cout << "-1";
			return 0;
		}
		sort( v.begin(), v.end() );
		num = n - 2;
		sum = n - 1;
		while ( true ) {
			while ( num > 0 && !v[ num ].first ) {
				num --;
			}
			while ( sum > 0 && !v[ sum ].first )
				sum --;
			if ( sum == num ) {
				num --;
				while ( num > 0 && !v[ num ].first )
					num --;
			}
			vv.push_back( make_pair( min( v[ num ].first, v[ sum ].first ), make_pair( v[ num ].second, v[ sum ].second ) ) );
			if ( v[ num ].first < v[ sum ].first ) {
				v[ sum ].first -= v[ num ].first;
				v[ num ].first = 0;
			}
			else {
				v[ num ].first -= v[ sum ].first;
				v[ sum ].first = 0;
			}
			if ( num == 0 && !v[ num ].first )	
				break;
		}
		cout << vv.size() << "\n";
		for ( auto i : vv )
			cout << i.first << " " << i.second.first << " " << i.second.second << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 280 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 1 ms 208 KB n=3
4 Correct 1 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 1 ms 208 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 280 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 1 ms 208 KB n=3
4 Correct 1 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 1 ms 208 KB n=2
7 Correct 1 ms 316 KB n=5
8 Incorrect 1 ms 208 KB Not all heaps are empty in the end
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 280 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 1 ms 208 KB n=3
4 Correct 1 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 1 ms 208 KB n=2
7 Correct 1 ms 316 KB n=5
8 Incorrect 1 ms 208 KB Not all heaps are empty in the end
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12588 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 280 KB n=4
2 Correct 0 ms 208 KB n=3
3 Correct 1 ms 208 KB n=3
4 Correct 1 ms 208 KB n=4
5 Correct 0 ms 208 KB n=4
6 Correct 1 ms 208 KB n=2
7 Correct 1 ms 316 KB n=5
8 Incorrect 1 ms 208 KB Not all heaps are empty in the end
9 Halted 0 ms 0 KB -