A. Arithmetic

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/A

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

You need to print 'Yes' if a*b==c or b*c==a or c*a==b.

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		if(a*b==c)
		{
			puts("YES");
			printf("%d %d %d\n",a,b,c);
		}
		else if(b*c==a)
		{
			puts("YES");
			printf("%d %d %d\n",b,c,a);
		}
		else if(c*a==b)
		{
			puts("YES");
			printf("%d %d %d\n",c,a,b);
		}
		else puts("NO");
	}
	return 0;
}

 

B. Fair Division

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/B

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

If n is dividable by 3, you need to print 'a/3-1', 'a/3', and 'a/3+1'.

If not, the answer does not exist. Print '-1'.

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;

int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a;
		scanf("%d",&a);
		if(a%3==0)
		{
			int k=a/3;
			printf("%d %d %d\n",k-1,k,k+1);
		}
		else puts("-1");
	}
	return 0;
}

 

C. Baking

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/C

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

You can compare |a-b| and |a-c|.

If |a-b| is smaller, print |a-b|+|b-c|.

Else, print |a-c|+|b-c|.

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(abs(a-b)<=abs(a-c))
	{
		printf("%d",abs(a-b)+abs(b-c));
	}
	else
	{
		printf("%d",abs(a-c)+abs(c-b));
	}
	return 0;
}

 

D. Cheese Factory

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/D

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

You can conduct a greedy solution.

Use the container that can contain the most for the customer that buys the most, and vice versa.

Therefore, you need to print the sum of the multiples of the first, second, and third biggest numbers in the sequence a[i] and b[i].

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a,b,c,d,e,f;
		scanf("%d %d %d\n%d %d %d",&a,&b,&c,&d,&e,&f);
		int m1,m2,m3,n1,n2,n3;
		m1=max3(a,b,c);
		m3=min3(a,b,c);
		m2=a+b+c-m1-m3;
		n1=max3(d,e,f);
		n3=min3(d,e,f);
		n2=d+e+f-n1-n3;
		printf("%d\n",m1*n1+m2*n2+m3*n3);
	}
	return 0;
}

 

 

+ Recent posts