forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCS_Digital pipequestion.cpp
47 lines (42 loc) · 909 Bytes
/
TCS_Digital pipequestion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
using namespace std;
int main()
{
int N,M,R, incoming[1000],outgoing[1000],actin[1000],acout[1000];
int totin, totout;
cin>>N>>M>>R;
if((N||M||R))
{
for(int i=0; i<N; i++)
{
cin>>incoming[i];
actin[i]= incoming[i]-R;
}
for(int i=0; i<M; i++)
{
cin>>outgoing[i];
acout[i]= outgoing[i]-R;
}
totin = 0;
totout=0;
for (int i=0;i<N;i++){
totin += actin[i];
}
for (int i=0;i<M;i++){
totout += acout[i];
}
int addpipe;
addpipe =(totin-totout)+R;
if (totin == totout){
cout<<"BALANCED";
}
else{
cout<<addpipe;
}
}
else
{
cout<<"Invalid input";
}
return 0;
}