SPLITBIL - Editorial

PROBLEM LINK:

Practice
Contest : CodeShake

Author: Amruta Patil
Co-author: Shikha Shetgeri
Tester: Shikha Shetgeri
Editorialist: Amruta Patil

DIFFICULTY:

EASY

PREREQUISITES:

Basic Math, arrays

PROBLEM:

Aman and Aditi were out on a dinner, they plan to split the bill in a fair Manner, Each person get’s to eat one dish of their own choice while the other dishes will be shared among them. They have to pay full amount for the dish they ate and none for the dish that was ordered by the other person, however, the remaining amount should be divided among the two of them.

QUICK EXPLANATION:

f the no of dishes ordered is 4,(n=4),the bill is as follows: total=[10,20,30,40], Aman has ordered total[1] and Aditi has ordered total[3].
Therefore, the amount to be paid by Aman is, 20+((10+30)/2)=40 and the amount to be paid by Aditi is 40+((10+30)/2)=60.

SOLUTIONS:

Setter's Solution
#include<iostream>
using namespace std;
int main() {
    int n,a,b; cin>>n>>a>>b; 
    int arr[n];
    for(int i=0;i<n;i++){
             cin>>arr[i];
    } 
        int a_pay=0,b_pay=0,com=0; 
        for(int i=0;i<n;i++){ 
            if(arr[i]!=arr[a] && arr[i]!=arr[b]){
	    com += arr[i];
        } 
        } //to calculate payments 
        a_pay=arr[a]+com/2;
        b_pay=arr[b]+com/2; 
        cout<<a_pay<<" "<<b_pay<<endl; 
}