답안 #495050

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495050 2021-12-18T03:59:59 Z vinnipuh01 Gift (IZhO18_nicegift) C++17
7 / 100
67 ms 12528 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;
		}
		for ( auto i : vv ) {
			a[ i.second.first ] -= i.first;
			a[ i.second.second ] -= i.first;
		}
		sum = 0;
		for ( int i = 1; i <= n; i ++ )
			sum += a[ i ];
		if ( !sum ) {
			cout << vv.size() << "\n";
			for ( auto i : vv )
				cout << i.first << " " << i.second.first << " " << i.second.second << "\n";
		}
		else
			cout << "-1\n";
	}
}

/*

7 2
14 12 12 6 4 20 18
5
18 7 6
2 1 6
12 3 1
6 4 2
4 5 2

14 12 12 6 4 2 0
12 12 12 6 4 0 0
0 12 0 6 4 0 0
0 6 0 0 4 0 0
0 2 0 0 0 0 0

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 312 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 1 ms 308 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 312 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 1 ms 308 KB n=2
7 Correct 1 ms 204 KB n=5
8 Correct 0 ms 280 KB n=8
9 Incorrect 1 ms 300 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 312 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 1 ms 308 KB n=2
7 Correct 1 ms 204 KB n=5
8 Correct 0 ms 280 KB n=8
9 Incorrect 1 ms 300 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 12528 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 312 KB n=3
3 Correct 0 ms 204 KB n=3
4 Correct 1 ms 204 KB n=4
5 Correct 0 ms 204 KB n=4
6 Correct 1 ms 308 KB n=2
7 Correct 1 ms 204 KB n=5
8 Correct 0 ms 280 KB n=8
9 Incorrect 1 ms 300 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -