# WATERFLOW - Editorial

Setter: S.Manuj Nanthan
Tester: Harris Leung
Editorialist: Trung Dang

483

None

# PROBLEM:

Alice has a bucket of water initially having W litres of water in it. The maximum capacity of the bucket is X liters.

Alice turned on the tap and the water starts flowing into the bucket at a rate of Y litres/hour. She left the tap running for exactly Z hours. Determine whether the bucket has been overflown, filled exactly, or is still left unfilled.

# EXPLANATION:

The amount of water at the end is W + Y \cdot Z. We then compare this quantity to see whether it is equal to (or larger than/smaller than) X.

# TIME COMPLEXITY:

Time complexity is O(1) per test case.

# SOLUTION:

Preparer's Solution
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

int test_cases;
cin>>test_cases;
for(int tc = 1 ; tc <= test_cases ; tc++)
{
int initial_water , capacity , flow_rate , flow_hours;
cin>>initial_water>>capacity>>flow_rate>>flow_hours;

int total_water = initial_water + (flow_hours * flow_rate);

if(total_water > capacity)
cout<<"OverFlow"<<endl;
else if(total_water == capacity)
cout<<"Filled"<<endl;
else
cout<<"UnFilled"<<endl;

}

return 0;
}

Tester's Solution
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
ll n;
void solve(){
ll w,x,y,z;cin >> w >> x >> y >> z;
if(w+y*z>x) cout << "overflow\n";
else if(w+y*z==x) cout << "filled\n";
else cout << "unfilled\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int t;cin >> t;while(t--) solve();
}

Editorialist's Solution
#include <bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--) {
int w, x, y, z; cin >> w >> x >> y >> z;
int tar = w + y * z;
cout << (tar == x ? "filled" : tar < x ? "unfilled" : "overflow") << '\n';
}
}