baekjoon 20260211

This commit is contained in:
songyc macbook 2026-02-11 22:49:44 +09:00
parent 6b8a5a1308
commit 1c0306e017
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import sys
input = sys.stdin.readline
ans = 0
for i in range(int(input())) :
if i == 0 :
ans += int(input())
else :
ans = ans - 1 + int(input())
print(ans)

View File

@ -0,0 +1,60 @@
export {};
const input = require("fs").readFileSync(0).toString().trim().split('\n');
const T: number = Number(input[0]);
const [n, m]: number[] = [Number(input[1]), Number(input[3])];
const A: number[] = input[2].split(" ").map(Number);
const B: number[] = input[4].split(" ").map(Number);
let sumA: number[] = [];
for(let i=0; i<n; i++) {
let temp: number = 0
for(let j=i; j<n; j++) {
temp += A[j];
sumA.push(temp);
}
}
let sumB: number[] = [];
for(let i=0; i<m; i++) {
let temp: number = 0
for(let j=i; j<m; j++) {
temp += B[j];
sumB.push(temp);
}
}
sumA.sort((a,b) => a - b);
sumB.sort((a,b) => b - a);
const [N, M]: number[] = [sumA.length, sumB.length];
let [ptA, ptB]: number[] = [0, 0];
let ans: number = 0;
while (ptA < N && ptB < M) {
const curr: number = sumA[ptA] + sumB[ptB];
if(curr !== T ) {
if(T > curr) ptA++;
else if(T < curr) ptB++;
continue;
}
let cntA: number = 0;
let valA: number = sumA[ptA];
while(ptA < N && sumA[ptA] === valA) {
cntA++;
ptA++;
}
let cntB: number = 0;
let valB: number = sumB[ptB];
while(ptB < M && sumB[ptB] === valB) {
cntB++;
ptB++;
}
ans += cntA*cntB;
}
console.log(ans);