AC代码: void CountNumbers() { int n; cin >> n; vector<long long>ones = { 11, 111}; vector<long long >nums(n); int cnt = 0; for (int i = 0; i < n; ++i) { cin >> nums[i]; if (nums[i] % 11 == 0 || nums[i] % 111 == 0) { cnt++; continue; } long long b = nums[i] % 11; int mul = b; while (true) { if (nums[i] - 111 * mul > 0) { if ((nums[i] - 111 * mul) % 11 == 0) { cnt++; break; } mul += 11; } else break; } } cout << cnt << endl; } void maxCountGoods() { int n; cin >> n; vector<long long>happy_value(n); for (int i = 0; i < n; ++i) { cin >> happy_value[i]; } priority_queue<long long,vector<long long>, greater<long long> >qu; long long now = 0, cnt = 0; for (int i = 0; i < n; ++i) { now += happy_value[i]; cnt++; if (happy_value[i] < 0) qu.push(happy_value[i]); while(now < 0 && !qu.empty()) { now -= qu.top(); qu.pop(); cnt--; } } cout << cnt << endl; }
点赞 9
牛客网
牛客企业服务