This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using llu = unsigned long long;
using str = string;
// pairs
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdb = pair<db,db>;
#define mp make_pair
#define fr first
#define sc second
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pii>;
using vpl = V<pll>;
using vpd = V<pdb>;
#define ms0(x) memset(x , 0, sizeof(x))
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }
tcT> int upb(V<T>& a, const T& b) { return int(ub(all(a),b)-bg(a)); }
// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
const int MOD = (int)2019201949; // 998244353;
const int MX = (int)2e5+5;
const ll BIG = 1e18;
const db PI = acos((db)-1);
using ld = long double;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0);
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
void solve(){
int n;
cin >> n;
vector<pair<ld,ld>>a(n);
for (int i = 0; i<n; i++){
cin >> a[i].fr >> a[i].sc;
}
stack<pair<ld,ld>>s;
ld ans[n];
ans[0] = a[0].sc;
s.push(mp(a[0].sc, a[0].fr));
for (int i = 1; i<n; i++){
ld r = 0;
while(!s.empty()){
ld dist = ((ld)a[i].fr - s.top().sc) * ((ld)a[i].fr - s.top().sc) / ((ld) 4 * s.top().fr);
if (dist >= a[i].sc){
//can fully inflate
r = min(dist, (ld)a[i].sc);
break;
}else{
//cannot fully inflate
r = dist;
s.pop();
}
}
ans[i] = r;
s.push(mp(r, a[i].fr));
}
for (int i = 0; i < n; i++)cout<<ans[i]<<'\n';
}
int main() {
setIO("");
cout<<fixed<<setprecision(3);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
solve();
return 0;
}
Compilation message (stderr)
bal.cpp: In function 'void setIO(std::string)':
bal.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bal.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |