标签:def 范围 min contest space codeforce 表示 tps cin
\(pos\)在\(x_i\)的左边,则只需扩展\(x_i\)的左侧\(f[pos][1] = min(f[pos][1],min(f[max(x[j]-s[j]-1,0)][1],f[max(x[j]-s[j],0)][0]));\)
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int f[N][2],s[N],x[N];
int main()
{
int n,m;
cin >> n >> m;
for (int i = 1; i <= m; i++) f[i][0]=i-1,f[i][1]=1<<30;
f[0][1] = 0;
for (int i = 1; i <= n; i++)
{
cin >> x[i] >> s[i];
}
for (int i = 1; i<= m; i++)
for (int j = 1; j <= n;j++)
if ( i >= x[j])
{
f[i][1] = min(f[i][1],f[max(2*x[j]-i-1,0)][1]+max(i-x[j]-s[j],0));
f[i][1] = min(f[i][1],f[max(2*x[j]-i-1,0)][0]+1+max(i-x[j]-s[j],0));
}
else
{
f[i][1] = min(f[i][1],f[max(x[j]-s[j]-1,0)][1]);
f[i][1] = min(f[i][1],f[max(x[j]-s[j],0)][0]);
}
cout << f[m][1] << endl;
}
Codeforces Round #600 (Div. 2) E. Antenna Coverage
标签:def 范围 min contest space codeforce 表示 tps cin
原文地址:https://www.cnblogs.com/7osen/p/11875441.html