Question: Chinese question, not explained
Idea: Simply solve the equation. Set the elevator to rise a at a time, drop B at a time, and press the button n times in total, and press the push button X times, then, the elevator is located at a * X-B * (N-x). Just find the minimum positive value that satisfies this formula. There are a total of 2000 elevators. You can find the minimum value for each elevator.
AC code:
# Include <iostream> # include <cstdio> # include <string. h> using namespace STD; struct house {int Up, down;} HH [2012]; int fun (int x, int y, int N) {int num = (y * N)/(x + y); int mod = (y * n) % (x + y); If (mod = 0) {return X + Y;} else {int ans = (Num + 1) * (x + y)-(y * n); Return ans ;}} int main () {int n, m; while (~ Scanf ("% d", & N, & M) {int X; int ans = 100000000; For (INT I = 0; I <m; ++ I) {scanf ("% d", & HH [I]. up, & HH [I]. down); X = fun (HH [I]. up, HH [I]. down, n); If (x <ans) ans = x;} printf ("% d \ n", ANS);} return 0 ;}