您的位置:首页 > 其它

hdu 5265 pog loves szh II

2015-06-09 19:34 267 查看
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5265

原先用二分写挂了,估计边界没处理好,换了set好歹过了,罪过,罪过。。

[code]#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<set>
using std::multiset;
using std::max;
const int Max_N = 100010;
typedef unsigned long long ull;
ull n, p, arr[Max_N];
void solve() {
    ull res = 0;
    multiset<ull> rec;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &arr[i]);
        rec.insert(arr[i] %= p);
    }
    multiset<ull>::iterator ite;
    for (int i = 0; i < n; i++) {
        rec.erase(rec.find(arr[i]));
        ite = rec.lower_bound(p - arr[i]);
        ull v1 = *--ite;
        ite = rec.lower_bound(2 * p - arr[i]);
        ull v2 = *--ite;
        res = max(res, max((v1 + arr[i]) % p, (v2 + arr[i]) % p));
        rec.insert(arr[i]);
    }
    printf("%lld\n", res);
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w+", stdout);
#endif
    while (~scanf("%lld %lld", &n, &p)) solve();
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: