n, cap, limit = map(int, input().split())boxes = list(map(int, input().split()))loaded = total = sent = 0stop = 0for i, w in enumerate(boxes, start=1): if w > limit: # 너무 무거운 상자: 따로 보내고 다음 상자로 sent += 1 continue if total + w > cap: # 실으면 넘친다: 여기서 아예 멈춘다 stop = i break loaded += 1 total += wprint(loaded, total, sent, stop)
JavaScriptmain.js · 19 行
const [n, cap, limit, ...boxes] = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);let loaded = 0;let total = 0;let sent = 0;let stop = 0;for (let i = 0; i < n; i++) { const w = boxes[i]; if (w > limit) { sent++; continue; // 이 상자만 건너뛴다 } if (total + w > cap) { stop = i + 1; break; // 반복 전체를 끝낸다 } loaded++; total += w;}console.log(`${loaded} ${total} ${sent} ${stop}`);
TypeScriptmain.ts · 20 行
import { readFileSync } from "node:fs";const [n, cap, limit, ...boxes]: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);let loaded = 0;let total = 0;let sent = 0;let stop = 0;for (let i = 0; i < n; i++) { const w: number = boxes[i]; if (w > limit) { sent++; continue; // 이 상자만 건너뛴다 } if (total + w > cap) { stop = i + 1; break; // 반복 전체를 끝낸다 } loaded++; total += w;}console.log(`${loaded} ${total} ${sent} ${stop}`);
JavaMain.java · 30 行
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int cap = Integer.parseInt(st.nextToken()); int limit = Integer.parseInt(st.nextToken()); st = new StringTokenizer(in.readLine()); int loaded = 0, total = 0, sent = 0, stop = 0; for (int i = 1; i <= n; i++) { int w = Integer.parseInt(st.nextToken()); if (w > limit) { sent++; continue; // 이 상자만 건너뛴다 } if (total + w > cap) { stop = i; break; // 반복 전체를 끝낸다(남은 수는 읽지 않아도 된다) } loaded++; total += w; } System.out.println(loaded + " " + total + " " + sent + " " + stop); }}
C#Main.cs · 30 行
using System;using System.Linq;class Program{ static void Main() { int[] first = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); int n = first[0], cap = first[1], limit = first[2]; int[] boxes = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); int loaded = 0, total = 0, sent = 0, stop = 0; for (int i = 0; i < n; i++) { int w = boxes[i]; if (w > limit) { sent++; continue; // 이 상자만 건너뛴다 } if (total + w > cap) { stop = i + 1; break; // 반복 전체를 끝낸다 } loaded++; total += w; } Console.WriteLine($"{loaded} {total} {sent} {stop}"); }}
C++main.cpp · 25 行
#include <iostream>#include <vector>int main() { std::ios::sync_with_stdio(false); int n, cap, limit; std::cin >> n >> cap >> limit; std::vector<int> boxes(n); for (int& w : boxes) std::cin >> w; int loaded = 0, total = 0, sent = 0, stop = 0; for (int i = 0; i < n; i++) { int w = boxes[i]; if (w > limit) { sent++; continue; // 이 상자만 건너뛴다 } if (total + w > cap) { stop = i + 1; break; // 반복 전체를 끝낸다 } loaded++; total += w; } std::cout << loaded << " " << total << " " << sent << " " << stop << "\n";}
Cmain.c · 22 行
#include <stdio.h>int main(void) { int n, cap, limit, w; int loaded = 0, total = 0, sent = 0, stop = 0; scanf("%d %d %d", &n, &cap, &limit); for (int i = 1; i <= n; i++) { scanf("%d", &w); if (w > limit) { sent++; continue; /* 이 상자만 건너뛴다 */ } if (total + w > cap) { stop = i; break; /* 반복 전체를 끝낸다 */ } loaded++; total += w; } printf("%d %d %d %d\n", loaded, total, sent, stop); return 0;}
Craykonmain.cray · 26 行
first = 控制台.读数字();n = first[0];cap = first[1];limit = first[2];boxes = 控制台.读数字();loaded = 0;total = 0;sent = 0;stop = 0;循环 (i = 0; i < n; i++){ w = boxes[i]; 如果 (w > limit) { sent++; 继续; // 이 상자만 건너뛴다 } 如果 (total + w > cap) { stop = i + 1; 跳出; // 반복 전체를 끝낸다 } loaded++; total += w;}控制台.输出(loaded + " " + total + " " + sent + " " + stop);