成都网站制作计划,seo方案怎么做,手机端网站开发流程,美食网站黑米如何做题目传送门 1 /*2 贪心/二分查找#xff1a;首先对ai%p#xff0c;然后sort#xff0c;这样的话就有序能使用二分查找。贪心的思想是每次找到一个aj使得和为p-1(如果有的话)3 当然有可能两个数和超过p#xff0c;那么an的值最优#xff0c;每次还要和… 题目传送门 1 /*2 贪心/二分查找首先对ai%p然后sort这样的话就有序能使用二分查找。贪心的思想是每次找到一个aj使得和为p-1(如果有的话)3 当然有可能两个数和超过p那么an的值最优每次还要和an比较4 注意不能选取两个相同的数5 反思比赛时想到了%p和sortlower_bound但是还是没有想到这个贪心方法保证得出最大值还是题目做的少啊(6 */7 #include cstdio8 #include algorithm9 #include cstring
10 #include cmath
11 using namespace std;
12
13 typedef long long ll;
14 const int MAXN 1e5 10;
15 const int INF 0x3f3f3f3f;
16 ll a[MAXN];
17
18 int main(void) //BestCoder Round #43 1002 pog loves szh II
19 {
20 // freopen (B.in, r, stdin);
21
22 int n; ll p;
23 while (scanf (%d%I64d, n, p) 2)
24 {
25 for (int i1; in; i) {scanf (%I64d, a[i]); a[i] % p;}
26 sort (a1, a1n);
27
28 ll ans 0;
29 for (int i1; in; i)
30 {
31 int pos lower_bound (a1i, a1n, p - a[i]) - a; pos--;
32 if (pos n pos ! i) ans max (ans, (a[i] a[pos]) % p);
33 if (i ! n) ans max (ans, (a[i] a[n]) % p);
34 }
35
36 printf (%I64d\n, ans);
37 }
38
39 return 0;
40 } 转载于:https://www.cnblogs.com/Running-Time/p/4560261.html