#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 100000
using namespace std;

int p,k,lx,ly,rx,ry,num=1,py;
int m[M],n[M];
double mn,mx;

inline void Read(){
	scanf("%d",&p);
	scanf("%d%d",&m[1],&n[1]);
	while(scanf("%d%d",&rx,&ry)){
		if(rx==-1&&ry==-1) break;
		int lx=m[num],ly=n[num];
		for(int i=lx+1;i<=rx;i++){
			num++;
			m[num]=m[num-1]+1;
			n[num]=n[num-1]+(ry-ly)/(rx-lx);
		}
	}
	scanf("%d",&k);
}

int main(){
	Read();
	if(p>=m[num]){
		lx=m[num],ly=n[num];
		for(int i=lx+1;i<=p+1;i++){
			num++;
			m[num]=m[num-1]+1;
			n[num]=n[num-1]-k;
		}
	}
	for(int i=1;i<=num;i++)
		if(m[i]==p){
			py=n[i];
			break;
		}
	mn=-0x3f3f3f3f,mx=0x3f3f3f3f;
	for(int i=1;i<=num;i++)
		if(py-n[i]>0)
			mn=max(mn,(double)((m[i]-m[1])*n[i]-(double)(p-m[1])*py)/(double)(py-n[i]));
		else
			mx=min(mx,(double)((m[i]-m[1])*n[i]-(double)(p-m[1])*py)/(double)(py-n[i]));
	if(mn>mx) 
		printf("NO SOLUTION\n"); 
	else
		if(mn>0) 
			printf("%.0lf",ceil(mn));
		else
			if(mx<0)
				printf("%.0lf",floor(mx));
			else
				printf("0");
    return 0;
}

 

0 0 votes
文章评分
订阅这个评论
提醒

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

0 评论
最旧
最新 得票最多
Inline Feedbacks
View all comments