AtCoder ABC 017 A&B&C AtCoder - 017
private void solveA() {
int res = 0;
for (int i = 0; i < 3; i++) {
int point = nextInt();
int ratio = nextInt();
res += point * ratio / 10;
}
out.println(res);
}
--If'ch''o''k''u'is included, it will not be a choku word --If you replace all'ch''o''k''u'with empty strings, the length of the input value becomes 0. ――I think it's okay to check one by one instead of replacing, but java is easier to replace.
private void solveB() {
String res = next().replaceAll("ch", "").replaceAll("o", "").replaceAll("k", "").replaceAll("u", "");
out.println(res.length() == 0 ? "YES" : "NO");
}
--From the problem
-Don't take all kinds of jewels
――Which of the 1-n types of gems is the most rewarding to not take? Can be read as
―― Which ruins are you exploring? Which gem should not be taken, not
? Think with `
――If you want to take a certain kind of gemstone, you should also take all the same kind of gemstones from other archaeological sites.
--If you read the question, it will be find the maximum score when you do not take a certain jewel
.
-$ If you don't take jewel 1, if you don't take jewel 2, if you don't take jewel 3 ... If you don't take jewel N $
――If you simply turn the loop, it will never be in time, so try it like a cumulative sum
--Input example 1:
4 6 1 3 30 2 3 40 3 6 25 6 6 10
――For example, if you decide not to take 1 jewel, it will be as follows --You can't go to Ruins 1 --Ruins 2 and 3 can be reached --Ruins 4 cannot be visited --If you do not take 1-3, you will not get this score, but if you decide not to take 4-6, you will get this score.
Jewel 1 | Jewel 2 | Jewel 3 | Jewel 4 | Jewel 5 | Jewel 6 | |
---|---|---|---|---|---|---|
Ruins 1 | 30 | 30 | 30 | |||
Ruins 2 | 40 | 40 | 40 | 40 | ||
Ruins 3 | 25 | 25 | ||||
Ruins 4 | 10 | 10 | 10 | 10 | 10 | |
total (Maximum value without jewels) |
75 | 35 | 10 | 80 | 80 | 70 |
――If this is the case, the last one will not be included
――However, I felt that the cumulative sum part could be implemented by the Imos method
, so I tried another solution.
private void solveC2() {
int n = nextInt();
int m = nextInt();
int[] l = new int[n];
int[] r = new int[n];
int[] s = new int[n];
int[][] res = new int[m + 1][1];
for (int i = 0; i < n; i++) {
l[i] = nextInt();
r[i] = nextInt();
s[i] = nextInt();
for (int j = 1; j <= m; j++) {
if (j < l[i] || r[i] < j) {
res[j][0] += s[i];
}
}
}
Arrays.sort(res, (x, y) -> -Integer.compare(x[0], y[0]));
out.println(res[0][0]);
}
--Reference site (potato method and cumulative sum) -Imotz method -Summary of imos method / cumulative sum problem in competitive programming -Be able to write the cumulative sum without thinking! - ABC - 035- A&B&C
Corrected the following part of the above solution
for (int j = 1; j <= m; j++) {
if (j < l[i] || r[i] < j) {
res[j][0] += s[i];
}
}
private void solveC() {
int n = nextInt();
int m = nextInt();
int[] l = new int[n];
int[] r = new int[n];
int[] s = new int[n];
int[] res = new int[m];
for (int i = 0; i < n; i++) {
l[i] = nextInt() - 1;
r[i] = nextInt() - 1;
s[i] = nextInt();
res[0] += s[i];
res[l[i]] -= s[i];
if (r[i] < m - 1) {
res[r[i] + 1] += s[i];
}
}
for (int i = 1; i < res.length; i++) {
res[i] = res[i] + res[i - 1];
}
Arrays.sort(res);
out.println(res[m - 1]);
}
Recommended Posts