---
# System prepended metadata

title: 12078 - Hurry!
tags: [NTHUOJ]

---

# 12078 - Hurry!
## 題解:
直接模擬就可以了
用迴圈去尋找最佳的位子, 然後再用迴圈更新ri和li
## Code:
```c=1
#include <stdio.h>
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)

int main(){
    int t, n, k;
    scanf("%d", &t);
    while(t--){
        int ans = 0, r[3005] = {0}, l[3005] = {0}, used[3005] = {0};
        scanf("%d%d", &n, &k);
        for (int i = 1; i <= n; i++) // initiate
            r[i] = n - i, l[i] = i - 1;
        while(k--){
            int max = -1, idx = 0;
            for (int i = 1; i <= n; i++){
                if(used[i])
                    continue;
                if(min(r[i], l[i]) > max){
                    max = min(r[i], l[i]);
                    idx = i;
                }
            }
            used[idx] = 1;
            for (int i = 1; i <= n; i++){
                if(i == idx)
                    r[i] = l[i] = 0;
                else if(i < idx && i + r[i] + 1 > idx)
                    r[i] = idx - i - 1;
                else if(i > idx && i - l[i] - 1 < idx)
                    l[i] = i - idx - 1;
            }
            ans = idx;
        }
        printf("%d\n", ans);
    }
    return 0;
}
```
###### tags: `NTHUOJ`