Codeforces - 1153A - Serval and Bus

地址

https://codeforces.com/contest/1153/problem/A

原文地址

https://www.lucien.ink/archives/413

代码

https://pasteme.cn/6247

#include <bits/stdc++.h>
int main() {
    int n, m, min = 0x3f3f3f3f, ans, buf;
    scanf("%d%d", &n, &m);
    for (int i = 1, a, d; i <= n; i++) {
        scanf("%d%d", &a, &d);
        if (a >= m) buf = a - m;
        else {
            buf = d - (m - a) % d;
            if (buf >= d) buf -= d;
        }
        if (buf < min) min = buf, ans = i;
    }
    printf("%d\n", ans);
    return 0;
}

发表留言

人生在世,错别字在所难免,无需纠正。