记录编号 387592 评测结果 AAAAAAAAAA
题目名称 [HAOI 2014]走出金字塔 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.012 s
提交时间 2017-03-26 21:10:44 内存使用 0.31 MiB
显示代码纯文本
/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>
#define MAXN 10233
using namespace std;
inline int read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}
/*-----------------------------------------------------------------------------*/

int n, m, k, s, xa, ya, ans = 168430090;



inline void init() {
	n = read();
	m = read();
	k = read();
	s = read();
	xa = read();
	ya = read();
}

int to(int xf, int yf, int xt, int yt) {
	if(xt > xf ^ yt > yf) return abs(yf - yt) + abs(xf - xt) * 2;
	else return max(abs(yt - yf), abs(xt - xf) * 2) - ((xf & 1) == (xt & 1) && (abs(yf - yt) & 1));
}

int main() {
#ifndef MYLAB
	freopen("ha14c.in", "r", stdin);
	freopen("ha14c.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
	init();
	for(int i = 1; i <= m; i++) {
		int xo = read();
		int yo = read();
		ans = min(ans, to(xa, ya, xo, yo));
	}

	ans = s - k * ans - 1;
	printf("%d", (ans >= 0? ans : -1));

	return 0;
}