522B. Photo to Remember - Codeforces Solution C++

  Problem Link : 522B. Photo to Remember 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main()
{
	int n;
	cin>>n;
	map<int,int> cnt;
	pair<int,int> arr[n];
	ll twidth=0,currW=0,currH;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i].first>>arr[i].second;
		cnt[arr[i].second]++;
		twidth+=arr[i].first;
	}

	for(int i=0;i<n;i++)
	{
		currW = twidth - arr[i].first;
		auto it = --cnt.end();
		if((*it).first == arr[i].second && (*it).second == 1 )
			currH = (*--it).first;
		else
			currH = (*it).first;
			
		cout<<currW * currH<<" ";	
	}
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!

  Problem Link : 522B. Photo to Remember 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main()
{
	int n;
	cin>>n;
	map<int,int> cnt;
	pair<int,int> arr[n];
	ll twidth=0,currW=0,currH;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i].first>>arr[i].second;
		cnt[arr[i].second]++;
		twidth+=arr[i].first;
	}

	for(int i=0;i<n;i++)
	{
		currW = twidth - arr[i].first;
		auto it = --cnt.end();
		if((*it).first == arr[i].second && (*it).second == 1 )
			currH = (*--it).first;
		else
			currH = (*it).first;
			
		cout<<currW * currH<<" ";	
	}
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!