complete at jungol 1077.py 3135.py 14020.py 3006.rs

This commit is contained in:
2026-07-29 22:28:56 +09:00
parent 8f06210897
commit 6a4ee13ce2
4 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import sys
input = sys.stdin.readline
if __name__ == "__main__":
n, w = map(int, input().split())
jewelries = [tuple(map(int, input().split())) for _ in range(n)]
dp = [0] * (w + 1)
for weight, price in jewelries:
for j in range(weight, w + 1):
dp[j] = max(dp[j], dp[j - weight] + price)
print(dp[w])

View File

@@ -0,0 +1,36 @@
import sys
input = sys.stdin.readline
if __name__ == "__main__":
n, q = map(int, input().split())
prices = list(map(int, input().split()))
if n <= 3:
s = sum(prices)
r1 = (100 - q) * s // 100
r2 = s - min(prices)
print(int(min(r1, r2)))
elif q == 0:
prices.sort()
s = 0
while len(prices) >= 3:
s += prices.pop()
s += prices.pop()
prices.pop()
s += sum(prices)
print(s)
elif q >= 34:
print(sum(prices) * (100 - q) // 100)
else:
prices.sort(reverse=True)
dp = [0] * (n + 1)
for i in range(1, n + 1):
dp[i] = dp[i - 1] + prices[i - 1] * (100 - q) // 100
g = 0
if i >= 3:
g = prices[i - 3] + prices[i - 2]
dp[i] = min(dp[i], dp[i - 3] + g)
print(dp[n])

View File

@@ -0,0 +1,16 @@
import sys
input = sys.stdin.readline
if __name__ == "__main__":
n = int(input())
arr = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(1, n + 1):
cum[i] = cum[i - 1] + arr[i - 1]
q = int(input())
for _ in range(q):
s, e = map(int, input().split())
print(cum[e] - cum[s - 1])

View File

@@ -0,0 +1,28 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let (n, m) = (iter.next().unwrap(), iter.next().unwrap());
let mut cumf = 2 % m;
let (mut f1, mut f2) = (1 % m, 1 % m);
if n == 1 {
println!("{}", f1);
} else if n == 2 {
println!("{}", cumf);
} else {
for _ in 3..=n {
let newf = (f2 + f1) % m;
cumf += newf;
cumf %= m;
f1 = f2;
f2 = newf;
}
println!("{}", cumf);
}
}