#define mod 1000000007 int breakfastNumber(int* staple, int stapleSize, int* drinks, int drinksSize, int x){ int cnt[100001] = {0}; for (int i=0; i<drinksSize; ++i) cnt[drinks[i]] += 1; for (int i=1; i<100001; ++i) cnt[i] += cnt[i-1]; long num = 0; for (int i=0; i<stapleSize; ++i) { int idx = x - staple[i]; if (idx >= 0) { idx = fmin(idx, 100000); num += cnt[idx]; if (num >= mod) num %= mod; } } return num; }