아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Annoyed Coworkers

시간 제한2초메모리 제한1024 MB

요약
각 동료의 초기 짜증이 a이고 도움을 요청할 때마다 d씩 오를 때, h번의 요청을 나눠 가장 짜증난 동료의 최종 짜증을 최소로 만든다.
난이도

보통10점 중 7점

유형
이분 탐색, 그리디, 수학
정답자
아직 제출이 없습니다

문제

A picture of you, not working. Source: XKCD 303

It's another day in the office, and you're a mastermind of not doing any work yourself. Instead, you'll go to your coworkers for "help," but secretly have them do all the work.

You've determined that the more one of your coworkers helps you, the more annoyed they become. You've also been able to determine how much more annoyed a coworker gets everytime you ask them for help. At the beginning of the day, a coworker is initially aa annoyed at you. That's their annoyance level. Everytime you ask them for help though, they become dd more annoyed at you -- their annoyance level aa increases by a constant amount dd so that a=a+da=a+d.

You want to complete a project of hh tasks solely with "help" from your coworkers, but you need to be careful not to annoy any of them too much.

What's the best you can do?

입력

The first line contains 22 integers hh and cc, where hh (1≤h≤100,0001 \le h \le 100\\,000) is the number of times you have to ask for help to complete the project, and cc (1≤c≤100,0001 \le c \le 100\\,000) denotes the number of coworkers you have.

Each of the following cc lines contains two positive integers aa and dd, representing a coworker whose initial annoyance level is aa and who is getting more annoyed at you by an increase of dd every time you ask them for help (1≤a,d≤1091\le a, d \le 10^9).

출력

Output a single number, which is the maximum annoyance level any coworker has at you provided you use an optimal strategy to minimize this level. (In other words, of all possible strategies, choose one that minimizes the annoyance level of the worker or workers who are most annoyed at you at the end.)

예제3

  1. 예제 1

    입력
    4 4
    1 2
    2 3
    3 4
    4 5
    
    예상 출력
    7
    
  2. 예제 2

    입력
    3 2
    1 1000
    1000 1
    
    예상 출력
    1002
    
  3. 예제 3

    입력
    5 2
    1 1
    2 2
    
    예상 출력
    5