PROBLEM LINK:
Author: Srinjoy Ray
Editorialist: Srinjoy Ray
DIFFICULTY:
CAKEWALK
PREREQUISITES:
None
PROBLEM:
We are required to find the net profit of Nicholas.
EXPLANATION:
We need to calculate the net profit of Nicholas. For that we need to calculate his total expense and his total revenue. The total revenue is going to be the sum of the cost prices of the N Christmas trees whereas the total expense is going to be the sum of the cost prices of the N Christmas trees and the rent X.
So,
NetProfit = \sum_{i=1}^{N} B_i - (\sum_{i=1}^{N} A_i + X)
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n,x;
cin>>n>>x;
int a[n],b[n],revenue=0,expenses=0,profit;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
for(int i=0;i<n;i++){
revenue+=b[i];
}
for(int i=0;i<n;i++){
expenses+=a[i];
}
expenses+=x;
profit = revenue - expenses;
cout<<profit<<'\n';
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}