提交时间:2024-01-07 14:28:15

运行 ID: 229969

#include<bits/stdc++.h> using namespace std; int x,y; double n; vector<double> a; vector<double> b; int main() { cin >> n; for(int i = 0;i < n;i++) { double ai,bi; cin >> ai >> bi; a.push_back(ai); b.push_back(bi); if(bi > ai) { cout << "error" << endl; return 0; } if(ai <= 0 && bi <= 0) { cout << "error" << endl; return 0; } } cin >> x >> y; if(y > x) { cout << "error" << endl; return 0; } double tmp1 = 0; double tmp2 = 0; double sum = 0; for(int i = 0;i < n;i++) { tmp1 += b[i]; sum += a[i]; } if(sum >= x) { tmp2 = sum - y; } if(tmp2 <= 0) { cout << "error" << endl; return 0; } if(tmp1 >= tmp2) { cout << fixed << setprecision(2) << tmp2 << endl; return 0; } cout << fixed << setprecision(2) << tmp1 << endl; return 0; }