Submission #128635

# Submission time Handle Problem Language Result Execution time Memory
128635 2019-07-11T07:50:36 Z jangwonyoung Sparklers (JOI17_sparklers) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n,k;
ll t;
ll x[100001];
pair<ll,int>st[100001];
bool got[100001];
bool solve(ll s){
	ll blood=s;
	int l=k,r=k;
	for(int i=1; i<n ;i++) got[i]=false;
	int lt=i;
	for(int i=1; i<n ;i++){
		if(st[i].fi>s){
			lt=i;
			reverse(st+lt,st+n);	
		}
		got[st[i].se]=true;
		while(got[l-1]){
			l--;
			blood-=x[l+1]-x[l];
			if(blood<0) return false;
			blood+=s;
		}
		while(got[r]){
			blood-=x[r+1]-x[r];
			if(blood<0) return false;
			blood+=s;
			r++;
		}
	}
	reverse(st+lt,st+n);	
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k >> t;
	for(int i=1; i<=n ;i++){
		cin >> x[i];
	}
	for(int i=1; i<n ;i++){
		st[i]={x[i+1]-x[i],i};
	}
	sort(st+1,st+n);
	ll l=0,r=1e9/t+1;
	while(l!=r){
		ll mid=(l+r)/2;
		if(solve(mid*t*2)) r=mid;
		else l=mid+1;
	}
	cout << l << endl;
}

Compilation message

sparklers.cpp: In function 'bool solve(ll)':
sparklers.cpp:15:9: error: 'i' was not declared in this scope
  int lt=i;
         ^