I wrote a O(NlogN) too, I overloaded the map<> comparator, we may wrote less code for this. For anyone who is interested:

int minSubArrayLen(int s, vector<int>& nums) {
int ans = INT_MAX;
int n = nums.size(), sum = 0;
//map<int, int, greater<pair<int,int> > > sum2pos; // BUG: the comparator is only for the "key" i.e. int, not the "key:val pair".
map<int, int, greater<int> > sum2pos;
sum2pos[0] = -1;
for(int i = 0; i < n; i++) {
sum += nums[i];
auto it = sum2pos.lower_bound(sum - s); // it->val will <= sum-s;
if(it != sum2pos.end()) ans = min(ans, i - it->second);
sum2pos[sum] = i;
}
return ans == INT_MAX ? 0 : ans;
}

Anyway, O(N) is the optimal, not O(NlogN)