标签:acm codeforces
 .现在只能选择一个数x变成y,序列中所有等于x的值都变成y,求最小的c
.现在只能选择一个数x变成y,序列中所有等于x的值都变成y,求最小的cconst int maxn = 110000;
LL ipt[maxn];
map<LL, vector<LL> > mp;
map<LL, vector<LL> >::iterator it;
int main()
{
    int n, m;
    while (~RII(n, m))
    {
        mp.clear();
        REP(i, m)
        {
            cin >> ipt[i];
        }
        REP(i, m)
        {
            if (i > 0 && ipt[i - 1] != ipt[i])
                mp[ipt[i]].push_back(ipt[i - 1]);
            if (i < m - 1 && ipt[i + 1] != ipt[i])
                mp[ipt[i]].push_back(ipt[i + 1]);
        }
        LL ans = 0;
        FC(it, mp)
        {
            vector<LL>& ipt = it->second;
            sort(all(ipt));
            LL t = 0, m = ipt[(LL)ipt.size() / 2];
            REP(i, ipt.size())
            {
                t += abs((it->first) - ipt[i]) - abs(m - ipt[i]);
            }
            ans = max(ans, t);
        }
        ans *= -1;
        REP(i, m - 1)
            ans += abs(ipt[i] - ipt[i + 1]);
        cout << ans << endl;
    }
    return 0;
}Codeforces Round #248 (Div. 1)——Ryouko's Memory Note,布布扣,bubuko.com
Codeforces Round #248 (Div. 1)——Ryouko's Memory Note
标签:acm codeforces
原文地址:http://blog.csdn.net/wty__/article/details/37902781