알고리즘/알고리즘 문제풀이

Codeforces Round #790 (Div. 4) - B

b1ackhand 2022. 5. 15. 23:02

문제 출처:

https://codeforces.com/contest/1676/problem/B

 

문제 분석:

구현

 

문제 해결:

박스안에 모두 같은 개수가 되려면 몇개를 빼야 되는가에 대한 문제이다

박스중 가장 작은값 찾아서 그만큼 다 빼주면 된다.

 

내 소스코드:

// freopen("input.txt", "r", stdin);
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <list>
#include <set>
#include <string.h>
#include <map>
#include <limits.h>
#include <stdlib.h>

#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 range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int INF = 987654321;
int testcase;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> testcase;

	while (testcase--)
	{
		int t;
		cin >> t;

		int arr[1002];
		int mini = INF;
		for (int i = 0; i < t; i++)
		{
			int tmp;
			cin >> tmp;
			mini = min(mini, tmp);
			arr[i] = tmp;
		}
		int sum = 0;
		for (int i = 0; i < t; i++)
		{
			sum += arr[i] - mini;
		}
		cout << sum << "\n";
	}

	return 0;
}

 

고찰: