Submission #1226244

#TimeUsernameProblemLanguageResultExecution timeMemory
1226244_rain_Sparklers (JOI17_sparklers)C++20
0 / 100
0 ms776 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N=(int)1e6;
	int x[N+2];
	int n,t,k;

bool possible(double s){
	long double rest=0;
	vector<double>v;
	s=s*2;
	for(int i=2;i<=n;++i){
		int length=x[i]-x[i-1];
		v.push_back((double)length/s);
	}
	sort(v.begin(),v.end());

	for(auto&x:v){
		if (t>x) rest+=(double)t-x;
		else {
			if (x-rest<=t) rest-=x-t;
				else return false;
		}
	}
	return true;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0) ; cout.tie(0);
	#define task "main"
	if (fopen(task".inp","r")){
		freopen(task".inp","r",stdin);
		freopen(task".out","w",stdout);
	}
	
	cin>>n>>k>>t;
	for(int i=1;i<=n;++i) cin>>x[i];
	
	int low=1,high=*max_element(x+1,x+n+1),ans=-1;
	while (low<=high){
		int mid=(low+high)/2;
		if (possible(mid)){
			ans=mid;
			high=mid-1;
		}
		else low=mid+1;
	}
	cout<<ans;
	
	return 0;
}

Compilation message (stderr)

sparklers.cpp: In function 'int main()':
sparklers.cpp:34:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |                 freopen(task".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:35:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |                 freopen(task".out","w",stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...