社区讨论

全红求条(玄关!!!)

P1103书本整理参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhj3dqhu
此快照首次捕获于
2025/11/03 20:04
4 个月前
此快照最后确认于
2025/11/03 20:04
4 个月前
查看原帖
代码如下
C
#include <bits/stdc++.h>
using namespace std;
map<int,int> c;
int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;
	cin >> n >> k;
	for (int i=1;i<=n;++i) {
		int x,y;
		cin >> x >> y;
		c[x] = y;
	}
	int ans = INT_MAX;
	for (auto i : c) {
		int x = i.first,y = i.second;
		c.erase(i.first);
		int cnt = 0,last = 0;
		for (auto j : c) {
			if (last) {
				cnt += abs(j.second - last);
			}
			last = j.second;
		}
		ans = min(ans,cnt);
		c[x] = y;
	}
	cout << ans << '\n';
	return 0;
} 

回复

0 条回复,欢迎继续交流。

正在加载回复...