解法:
双指针、贪心
#include <iostream>
#include <vector>
using namespace std;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> vec(n, 0);
for (int i = 0; i < n; i++) cin >> vec[i];
int l = 0, r = n - 1, min = 0;
while (l <= r) {
if (l == r) {
min++;
break;
}
if (vec[r] == k) {
min++,r--;
}
else if (vec[r] + vec[l] > k) {
min++,r--;
}
else if (vec[r] + vec[l] <= k) {
min++,r--, l++;
}
}
cout << min << endl;
return 0;
}