Business Center

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on PKU. Original ID: 3863
64-bit integer IO format: %lld      Java class name: Main

 
International Cyber Police Corporation (ICPC) had built a new mega-tall business center to host its headquarters and to lease some space for extra profit. It has so many floors, that it is impractical to have a separate button in each of its m elevator cars for each individual floor. Instead, each elevator car has just two buttons. One button in i-th elevator car makes it move up ui floors, the other makes it move down di floors. The business center is so high, that we can ignore its height for this problem (you will never reach the top floor), but you cannot go below the ground floor. All floors are numbered by integer numbers starting from zero, zero being the ground floor. 
You start on the ground floor of the business center. You have to choose one elevator car out of m to ride on. You cannot switch elevators cars after that. What is the lowest floor above the ground floor you can get to after you press elevator car buttons exactly n times?

 

Input

The first line of the input file contains two integer numbers n and m (1 <= n <= 1 000 000, 1 <= m <= 2 000) - the number of button presses and the number of elevator cars to choose from. The following m lines describe elevator cars. Each line contains two integer numbers ui and di (1 <= ui, di <= 1 000).

 

Output

Write to the output file a single positive integer number - the number of the lowest floor above ground floor that can be reached by one of m elevators after pressing its buttons exactly n times.

 

Sample Input

10 3
15 12
15 4
7 12

Sample Output

13

Source

 
解题:直接搞呗。。貌似要求必须至少上一次
 #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,m,u,d,ret;
void check() {
LL tmp = (n*d+u+d)/(u+d);
ret = min(ret,(u+d)*tmp - n*d);
}
int main() {
ios::sync_with_stdio(false);
cin>>n>>m;
ret = INT_MAX;
while(m--) {
cin>>u>>d;
check();
}
cout<<ret<<endl;
return ;
}

最新文章

  1. springmvc4环境简单搭建和定时任务
  2. springmvc中RedirectAttributes的作用
  3. 测试工具之Charles视频教程(更新中。。。)
  4. node的实践(项目一)
  5. js对字符串的操作
  6. NodeJs使用Mysql模块实现事务处理
  7. sys.default_constraints
  8. [NOIP1998]最大数
  9. linux磁盘限额配置:quota命令
  10. Java 数据结构与算法分析学习
  11. python3全栈开发-并发编程,多进程的基本操作
  12. 报错:Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: Lorg/apache/hadoop/fs/FileSystem
  13. 普通函数跟箭头函数中this的指向问题
  14. LINUX 手动建立SWAP文件及删除
  15. poj2632 【模拟】
  16. Ribbon Ping机制
  17. ansj
  18. Redis集群的主从切换研究
  19. Filter过滤器与Session会话跟踪技术
  20. L1-001 Hello World

热门文章

  1. Linux部署之批量自动安装系统之测试篇
  2. javascript常用代码(不完整版)
  3. swift语言点评十六-Initialization &amp;&amp; Deinitialization
  4. 基于 Token 的身份验证:JSON Web Token
  5. 紫书 习题 11-16 UVa 1669(树形dp)
  6. Docker之Mysql安装及配置
  7. Redis加入Centos Linux开机启动
  8. OCUI界面设计:滚动视图与分页控件初探
  9. 不安全的直接对象引用:你的 ASP.NET 应用数据是否安全?
  10. java 自定义实现base64编码转换