双指针扫描适用于有序数组,两个指针或同向或反向
对于这道题,若sum > m 则移动左指针,若sum < m,说明总和小了,移动右指针
当左端点超过m/2时,之后的连续自然数的和一定大于m
然而右端点超过后却不能说明总和大于m,因为若右端点只有一个数 那么左端点还是可以总和小于m/2的
而且m/2在c++下取整了。。。所以写右端点小于等于m/2最后可能取到小于m/2
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define debug(x) cerr << #x << "=" << x << endl;
const int MAXN = 2000000 +