QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649347#8242. V-DiagramAa#WA 0ms3732kbC++17771b2024-10-17 22:56:442024-10-17 22:56:45

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 22:56:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3732kb
  • [2024-10-17 22:56:44]
  • 提交

answer

#include <iostream>
#include <algorithm>
#define endl "\n"
using namespace std;
const double INF=1e18;
int n;
int a[300010];
double s[300010];
bool check(double mid){
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]+(double)a[i]-mid;
	double mi=INF;
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1]){
			mi=INF;
			continue;
		}
		else if(a[i]<a[i-1]) mi=min(mi,s[i-2]);
		else if(s[i]-mi>=0) return true;
	}
	return false;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		double l=0,r=0;
		cin >> n;
		for(int i=1;i<=n;i++){
			cin >> a[i];
			r=max(r,(double)a[i]);
		}
		while(r-l>1e-9){
			double mid=(l+r)/2;
			if(check(mid)) l=mid;
			else r=mid;
		}
		cout << r << endl;
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3732kb

input:

2
4
8 2 7 10
6
9 6 5 3 4 8

output:

6.75
5.83333

result:

wrong answer 2nd numbers differ - expected: '5.8333333', found: '5.8333300', error = '0.0000006'