complete jungol//2194.cpp and fix it
This commit is contained in:
43
storage/jungol/cpp/completed/2194.cpp
Normal file
43
storage/jungol/cpp/completed/2194.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
#define usize size_t
|
||||
using namespace std;
|
||||
|
||||
#define LIMIT (((usize) 1 << 63) - 1);
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
fastio();
|
||||
usize n, s;
|
||||
cin >> n >> s;
|
||||
let costs = vector<usize>(n);
|
||||
let yopps = vector<usize>(n);
|
||||
// it needs cost S for storing 1 litre of milk for a week.
|
||||
let cummin = vector<usize>(n);
|
||||
|
||||
for (usize i = 0; i < n; i++) {
|
||||
cin >> costs[i] >> yopps[i];
|
||||
}
|
||||
|
||||
let curr_min = (usize) LIMIT;
|
||||
|
||||
for (usize i = 0; i < n; i++) {
|
||||
curr_min = min(curr_min + s, costs[i]);
|
||||
cummin[i] = curr_min;
|
||||
}
|
||||
|
||||
let total = (usize) 0;
|
||||
for (usize i = 0; i < n; i++) {
|
||||
total += cummin[i] * yopps[i];
|
||||
}
|
||||
|
||||
cout << total << endl;
|
||||
}
|
||||
47
storage/jungol/cpp/completed/3521.cpp
Normal file
47
storage/jungol/cpp/completed/3521.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
#define usize size_t
|
||||
#define u64 uint64_t
|
||||
using namespace std;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
fastio();
|
||||
|
||||
let grams = vector<u64>{1, 2, 4, 8, 16};
|
||||
let counts = vector<u64>(5);
|
||||
|
||||
for (usize i = 0; i < 5; i++) {
|
||||
cin >> counts[i];
|
||||
}
|
||||
|
||||
usize n;
|
||||
cin >> n;
|
||||
|
||||
let usage = 0;
|
||||
let i = 4;
|
||||
while (i >= 0 && n > 0) {
|
||||
if (counts[i] > 0 && n >= grams[i]) {
|
||||
n -= grams[i];
|
||||
counts[i] -= 1;
|
||||
usage += 1;
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
if (n != 0) {
|
||||
cout << "impossible" << endl;
|
||||
} else {
|
||||
cout << usage << endl;
|
||||
}
|
||||
}
|
||||
50
storage/jungol/cpp/completed/4520.cpp
Normal file
50
storage/jungol/cpp/completed/4520.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#define let auto
|
||||
#define fn auto
|
||||
typedef size_t usize;
|
||||
using namespace std;
|
||||
|
||||
fn fastio() {
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
usize n, k;
|
||||
cin >> n >> k;
|
||||
let line = vector<char>(n);
|
||||
let valid = vector<bool>(n, false);
|
||||
for (usize i = 0; i < n; i++) {
|
||||
char t;
|
||||
cin >> t;
|
||||
|
||||
line[i] = t;
|
||||
if (t == 'H') {
|
||||
valid[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// left assoc
|
||||
|
||||
let count = 0;
|
||||
for (usize i = 0; i < n; i++) {
|
||||
if (line[i] == 'P') {
|
||||
let left = i >= k ? i - k : 0;
|
||||
let right = i + k >= n ? n - 1 : i + k;
|
||||
|
||||
for (usize j = left; j <= right; j++) {
|
||||
if (valid[j]) {
|
||||
count += 1;
|
||||
valid[j] = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user