This commit is contained in:
2025-12-28 12:04:25 +08:00
parent c0efe232d6
commit 5297b42c6e
4 changed files with 62 additions and 0 deletions

8
25/12/1351.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <vector>
class Solution {
public:
int countNegatives(std::vector<std::vector<int>>& grid) {
}
};

22
25/12/comp/28q1.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <algorithm>
#include <climits>
#include <vector>
class Solution {
public:
long long maximumScore(std::vector<int>& nums) {
std::vector<long long> pre;
int n = nums.size();
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += nums[i];
pre.push_back(sum);
}
int mins = nums[n - 1];
long long ans = pre[n-2] - mins;
for (int i = n - 3; i >= 0; i--) {
mins = std::min(mins,nums[i+1]);
ans = std::max(ans,pre[i] - mins);
}
return ans;
}
};

15
25/12/comp/28q2.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include <algorithm>
class Solution {
public:
long long minimumCost(int cost1, int cost2, int costBoth, int need1, int need2) {
if (costBoth >= cost1 + cost2) {
return (long long)cost1 * need1 + (long long)cost2 * need2;
}
int m1 = std::min(need1,need2);
long long a2 = (long long)std::max(need1,need2) * costBoth;
long long ans = (long long)m1 * costBoth;
ans += (long long)(need1 - m1) * cost1;
ans += (long long)(need2 - m1) * cost2;
return std::min(ans,a2);
}
};

17
25/12/comp/28q3.cpp Normal file
View File

@@ -0,0 +1,17 @@
class Solution {
public:
int minAllOneMultiple(int k) {
if (k%2==0 || k%5==0) {
return -1;
}
int remainder = 1;
for (int i = 1 ;i<=k;i++) {
if (remainder % k == 0) {
return i;
}
// (a * 10 + 1) % k = ((a % k) * 10 + 1) % k
remainder = (remainder * 10 + 1) % k;
}
return -1;
}
};