<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>累積和メニュー - IQパズルステップ</title>
	<atom:link href="https://chokomon.com/category/paiza/27-prefix_sum_problems/feed/" rel="self" type="application/rss+xml" />
	<link>https://chokomon.com</link>
	<description>ちょこっと頭を良くするIQパズル問題集</description>
	<lastBuildDate>Sun, 18 Sep 2022 06:21:56 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://chokomon.com/wp-content/uploads/2022/02/cropped-icon512-32x32.png</url>
	<title>累積和メニュー - IQパズルステップ</title>
	<link>https://chokomon.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【累積和メニュー】【区間の長さ】 区間の長さ 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-09-04-00654/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-09-04-00654/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sun, 18 Sep 2022 06:21:56 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1300]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6911</guid>

					<description><![CDATA[【累積和メニュー】> FINAL問題【区間の長さ】 区間の長さ 4 (paizaランク C 相当) [難易度: 1331 ±49] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_length_boss" target="_blank" rel="noreferrer noopener">FINAL問題【区間の長さ】 区間の長さ 4 (paizaランク C 相当)</a> [難易度: <strong>1331 ±49</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img fetchpriority="high" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-04-01.png" alt="" class="wp-image-6912"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, K が与えられます。</p>



<p>N 個の整数 a_1, a_2, ..., a_N からなる数列 a が与えられます。</p>



<p>この数列において、総和が K 以下の区間のうち、最大の長さを求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>10 15<br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>3</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));
    
    $maxLength = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $maxLength = max($maxLength, $r-$i-1);
    }
    echo $maxLength;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-04-02.png" alt="" class="wp-image-6913"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-09-04-00654/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間の長さ 3 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-09-03-00653/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-09-03-00653/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sun, 18 Sep 2022 04:38:10 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1200]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6906</guid>

					<description><![CDATA[【累積和メニュー】> 【区間の長さ】STEP: 3 区間の長さ 3 (paizaランク C 相当) [難易度: 1214 ±66] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_length_step3" target="_blank" rel="noreferrer noopener">【区間の長さ】STEP: 3 区間の長さ 3 (paizaランク C 相当)</a> [難易度: <strong>1214 ±66</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-03-01.png" alt="" class="wp-image-6907"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 K が与えられます。</p>



<p>10 個の整数 a_1, a_2, ..., a_10 からなる数列 a が与えられます。</p>



<p>この数列において、総和が K 以下の区間のうち、最大の長さを求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>15<br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>3</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $k = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    
    $maxLength = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $maxLength = max($maxLength, $r-$i-1);
    }
    echo $maxLength;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-03-02.png" alt="" class="wp-image-6908"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-09-03-00653/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間の長さ 2 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-09-02-00652/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-09-02-00652/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sun, 18 Sep 2022 04:06:57 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1000]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6901</guid>

					<description><![CDATA[【累積和メニュー】> 【区間の長さ】STEP: 2 区間の長さ 2 (paizaランク C 相当) [難易度: 1140 ±68] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_length_step2" target="_blank" rel="noreferrer noopener">【区間の長さ】STEP: 2 区間の長さ 2 (paizaランク C 相当)</a> [難易度: <strong>1140 ±68</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-02-01.png" alt="" class="wp-image-6902"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>10 個の整数 a_1, a_2, ..., a_10 からなる数列 a が与えられます。</p>



<p>この数列において、総和が 15 以下の区間のうち、最大の長さを求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>3</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $a = explode(" ", trim(fgets(STDIN)));
    
    $k = 15;
    $maxLength = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $maxLength = max($maxLength, $r-$i-1);
    }
    echo $maxLength;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-02-02.png" alt="" class="wp-image-6903"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-09-02-00652/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間の長さ 1 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-09-01-00651/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-09-01-00651/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Sun, 18 Sep 2022 03:54:43 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1400]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6896</guid>

					<description><![CDATA[【累積和メニュー】> 【区間の長さ】STEP: 1 区間の長さ 1 (paizaランク C 相当) [難易度: 1429 ±54] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_length_step1" target="_blank" rel="noreferrer noopener">【区間の長さ】STEP: 1 区間の長さ 1 (paizaランク C 相当)</a> [難易度: <strong>1429 ±54</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-01-01.png" alt="" class="wp-image-6897"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>以下の 10 個の整数からなる数列が与えられます。</p>



<p class="has-gray-background-color has-background">1 5 9 1 20 5 3 6 5 4</p>



<p></p>



<p>この数列において、総和が 15 以下の区間のうち、最大の長さを求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>なし</p>



<p><strong>出力値（例）</strong><br>与えられた数列において、総和が 15 以下の区間のうち、最も長いものの長さを求めてください。</p>



<p>末尾に改行を入れ、余計な文字、空行を含んではいけません。</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $a = [1, 5, 9, 1, 20, 5, 3, 6, 5, 4];
    
    $k = 15;
    $maxLength = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $maxLength = max($maxLength, $r-$i-1);
    }
    echo $maxLength;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-09-01-02.png" alt="" class="wp-image-6898"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-09-01-00651/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】【区間の数え上げ】 区間の数え上げ 4 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-08-04-00650/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-08-04-00650/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Fri, 16 Sep 2022 04:19:07 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1400]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6891</guid>

					<description><![CDATA[【累積和メニュー】> FINAL問題【区間の数え上げ】 区間の数え上げ 4 (paizaランク C 相当) [難易度: 1404 ±50] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_count_boss" target="_blank" rel="noreferrer noopener">FINAL問題【区間の数え上げ】 区間の数え上げ 4 (paizaランク C 相当)</a> [難易度: <strong>1404 ±50</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-04-01.png" alt="" class="wp-image-6892"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, K が与えられます。</p>



<p>2 行目に N 個の整数 a_1, a_2, ..., a_N からなる数列 a が与えられます。</p>



<p>この数列において、長さが 1 以上で総和が K 以下の区間がいくつあるか求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>10 15<br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>21</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));
    
    $count = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $count += $r-$i-1;
    }
    echo $count;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-04-02.png" alt="" class="wp-image-6893"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-08-04-00650/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間の数え上げ 3 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-08-03-00649/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-08-03-00649/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Fri, 16 Sep 2022 04:05:02 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1000]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6884</guid>

					<description><![CDATA[【累積和メニュー】> 【区間の数え上げ】STEP: 3 区間の数え上げ 3 (paizaランク C 相当) [難易度: 1188 ±62] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_count_step3" target="_blank" rel="noreferrer noopener">【区間の数え上げ】STEP: 3 区間の数え上げ 3 (paizaランク C 相当)</a> [難易度: <strong>1188 ±62</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-03-01.png" alt="" class="wp-image-6885"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 K が与えられます。</p>



<p>2 行目に 10 個の整数 a_1, a_2, ..., a_10 からなる数列 a が与えられます。</p>



<p>この数列において、長さが 1 以上で総和が K 以下の区間がいくつあるか求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>15<br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>21</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $k = trim(fgets(STDIN));
    $a = explode(" ", trim(fgets(STDIN)));
    
    $count = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $count += $r-$i-1;
    }
    echo $count;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-03-02.png" alt="" class="wp-image-6886"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-08-03-00649/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間の数え上げ 2 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-08-02-00648/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-08-02-00648/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Fri, 16 Sep 2022 03:31:35 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1400]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6878</guid>

					<description><![CDATA[【累積和メニュー】> 【区間の数え上げ】STEP: 2 区間の数え上げ 2 (paizaランク C 相当) [難易度: 1447 ±51] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_count_step2" target="_blank" rel="noreferrer noopener">【区間の数え上げ】STEP: 2 区間の数え上げ 2 (paizaランク C 相当)</a> [難易度: <strong>1447 ±51</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-02-01.png" alt="" class="wp-image-6879"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>10 個の整数 a_1, a_2, ..., a_10 からなる数列 a が与えられます。</p>



<p>この数列において、長さが 1 以上で総和が 15 以下の区間がいくつあるか求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>1 5 9 1 20 5 3 6 5 4</p>



<p><strong>出力値（例）</strong><br>21</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $a = explode(" ", trim(fgets(STDIN)));
    
    $k = 15;
    $count = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $count += $r-$i-1;
    }
    echo $count;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-02-02.png" alt="" class="wp-image-6880"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-08-02-00648/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】区間の数え上げ 1 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-08-01-00647/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-08-01-00647/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Fri, 16 Sep 2022 03:20:27 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1900]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6873</guid>

					<description><![CDATA[【累積和メニュー】> 【区間の数え上げ】STEP: 1 区間の数え上げ 1 (paizaランク C 相当) [難易度: 1954 ±50] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__syakutori_count_step1" target="_blank" rel="noreferrer noopener">【区間の数え上げ】STEP: 1 区間の数え上げ 1 (paizaランク C 相当)</a> [難易度: <strong>1954 ±50</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-01-01.png" alt="" class="wp-image-6874"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>この問題では、累積和と似たアルゴリズムである「しゃくとり法」について扱います。</p>



<p>しゃくとり法を用いることで、条件を満たす区間の数や、最も長い区間の長さを求めることができます。</p>



<p>この問題集を通してしゃくとり法の問題に触れ、少しずつしゃくとり法に慣れていきましょう。</p>



<p>まずは、問題を見てみましょう。</p>



<p>以下の 10 個の整数からなる数列が与えられます。<br></p>



<p class="has-gray-background-color has-background"> 1 5 9 1 20 5 3 6 5 4 </p>



<p></p>



<p>この数列において、長さが 1 以上で総和が 15 以下の区間がいくつあるか求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>なし</p>



<p><strong>出力値（例）</strong><br>与えられた数列において、総和が 15 以下の区間がいくつあるか求めてください。</p>



<p>末尾に改行を入れ、余計な文字、空行を含んではいけません。</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    $a = [1, 5, 9, 1, 20, 5, 3, 6, 5, 4];
    
    $k = 15;
    $count = 0;
    
    for ($i=0; $i&lt;count($a); $i++) {
        $r = $i+1;
        $sectionSum = 0;
        while ($r &lt; count($a)+1) {
            $sectionSum += $a[$r-1];
            if ($sectionSum &gt; $k) break;
            $r++;
        }
        $count += $r-$i-1;
    }
    echo $count;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-08-01-02.png" alt="" class="wp-image-6875"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-08-01-00647/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】【2 次元上のいもす法】 2 次元上のいもす法 6 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-07-06-00646/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-07-06-00646/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Thu, 15 Sep 2022 09:03:35 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1700]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6868</guid>

					<description><![CDATA[【累積和メニュー】> FINAL問題【2 次元上のいもす法】 2 次元上のいもす法 6 (paizaランク C 相当) [難易度: 1700 ±44] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__2d_imos_boss" target="_blank" rel="noreferrer noopener">FINAL問題【2 次元上のいもす法】 2 次元上のいもす法 6 (paizaランク C 相当)</a> [難易度: <strong>1700 ±44</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-07-06-01.png" alt="" class="wp-image-6869"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, M, K が与えられます。</p>



<p>2 行目に a_i, b_i, c_i, d_i (1 ≦ i ≦ K) が K 行で与えられます。</p>



<p>N 行 M 列のマスがあり、最初、マスには全て 0 が書かれています。</p>



<p>K 個の長方形領域の左上の座標 (a_i, b_i) と右下の座標 (c_i, d_i) が与えられます。それぞれの範囲に対して、その範囲に含まれるマスに 1 を加算していきます。</p>



<p>N 行 M 列のマスに書かれた値のうち、最大の値をいもす法を用いて求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>5 5 5<br>1 1 3 3<br>2 2 4 4<br>3 3 5 5<br>1 3 3 5<br>3 1 5 3</p>



<p><strong>出力値（例）</strong><br>5</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));
    
    $sRow = array_fill(0, $m+1, 0);
    $s = array_fill(0, $n+1, $sRow);
    
    for ($i=0; $i&lt;$k; $i++) {
        list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
        $x1[] = $a;
        $y1[] = $b;
        $x2[] = $c;
        $y2[] = $d;
        
        $s[$y1[$i]-1][$x1[$i]-1]++;
        $s[$y2[$i]][$x2[$i]]++;
        $s[$y1[$i]-1][$x2[$i]]--;
        $s[$y2[$i]][$x1[$i]-1]--;
    }
    
    // 横方向への累積和
    for ($i=0; $i&lt;$n+1; $i++) {
        for ($j=1; $j&lt;$m+1; $j++) {
            $s[$i][$j] += $s[$i][$j-1];
        }
    }
    
    // 縦方向の累積和
    for ($i=1; $i&lt;$n+1; $i++) {
        for ($j=0; $j&lt;$m+1; $j++) {
            $s[$i][$j] += $s[$i-1][$j];
        }
    }
    //print_r($s);
    
    // 最大値を調べる
    $tile_max = 0;
    for ($i=0; $i&lt;$n+1; $i++) {
        for ($j=0; $j&lt;$m+1; $j++) {
            if ($tile_max &lt; $s[$i][$j]) {
                $tile_max = $s[$i][$j];
            }
        }
    }
    echo $tile_max;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-07-06-02.png" alt="" class="wp-image-6870"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-07-06-00646/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【累積和メニュー】2 次元上のいもす法 5 (paizaランク C)-解答例-PHP編</title>
		<link>https://chokomon.com/27-prefix_sum_problems-07-05-00645/</link>
					<comments>https://chokomon.com/27-prefix_sum_problems-07-05-00645/#respond</comments>
		
		<dc:creator><![CDATA[東鳥子]]></dc:creator>
		<pubDate>Thu, 15 Sep 2022 08:44:23 +0000</pubDate>
				<category><![CDATA[paiza-問題集]]></category>
		<category><![CDATA[累積和メニュー]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ランクC]]></category>
		<category><![CDATA[難易度-1400]]></category>
		<guid isPermaLink="false">https://chokomon.com/?p=6861</guid>

					<description><![CDATA[【累積和メニュー】> 【2 次元上のいもす法】STEP: 5 2 次元上のいもす法 5 (paizaランク C 相当) [難易度: 1431 ±52] ※リンク先へ移動するためには[paiza]へのログインが必要です。 解答例]]></description>
										<content:encoded><![CDATA[
<p>【<a href="https://chokomon.com/paiza_mondai/27-prefix_sum_problems/">累積和メニュー</a>】> <a href="https://paiza.jp/works/mondai/prefix_sum_problems/prefix_sum_problems__2d_imos_step5" target="_blank" rel="noreferrer noopener">【2 次元上のいもす法】STEP: 5 2 次元上のいもす法 5 (paizaランク C 相当)</a> [難易度: <strong>1431 ±52</strong>]



<p>※リンク先へ移動するためには[<a href="https://paiza.jp/works" target="_blank" rel="noreferrer noopener">paiza</a>]へのログインが必要です。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="300" src="https://chokomon.com/wp-content/uploads/2022/09/27-07-05-01.png" alt="" class="wp-image-6862"/></figure>



<div class="wp-block-dvaux-frame sc_frame_wrap inline"><div class="sc_frame_title inline" style="background-color:#ccc">問題文</div><div class="sc_frame" style="background-color:#fff;border-color:#ccc">
<p>1 行目に整数 N, K が与えられます。</p>



<p>2 行目に a_i, b_i, c_i, d_i (1 ≦ i ≦ K) が K 行で与えられます。</p>



<p>N 行 N 列のマスがあり、最初、マスには全て 0 が書かれています。</p>



<p>K 個の長方形領域の左上の座標 (a_i, b_i) と右下の座標 (c_i, d_i) が与えられます。それぞれの範囲に対して、その範囲に含まれるマスに 1 を加算していきます。</p>



<p>N 行 N 列のマスに書かれた値のうち、最大の値をいもす法を用いて求めてください。</p>



<p></p>



<p><strong>入力値（例）</strong><br>5 5<br>1 1 3 3<br>2 2 4 4<br>3 3 5 5<br>1 3 3 5<br>3 1 5 3</p>



<p><strong>出力値（例）</strong><br>5</p>
</div></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">解答例</h2>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
    list($n, $k) = explode(" ", trim(fgets(STDIN)));
    
    $sRow = array_fill(0, $n+1, 0);
    $s = array_fill(0, $n+1, $sRow);
    
    for ($i=0; $i&lt;$k; $i++) {
        list($a, $b, $c, $d) = explode(" ", trim(fgets(STDIN)));
        $x1[] = $a;
        $y1[] = $b;
        $x2[] = $c;
        $y2[] = $d;
        
        $s[$y1[$i]-1][$x1[$i]-1]++;
        $s[$y2[$i]][$x2[$i]]++;
        $s[$y1[$i]-1][$x2[$i]]--;
        $s[$y2[$i]][$x1[$i]-1]--;
    }
    
    // 横方向への累積和
    for ($i=0; $i&lt;$n+1; $i++) {
        for ($j=1; $j&lt;$n+1; $j++) {
            $s[$i][$j] += $s[$i][$j-1];
        }
    }
    
    // 縦方向の累積和
    for ($i=1; $i&lt;$n+1; $i++) {
        for ($j=0; $j&lt;$n+1; $j++) {
            $s[$i][$j] += $s[$i-1][$j];
        }
    }
    //print_r($s);
    
    // 最大値を調べる
    $tile_max = 0;
    for ($i=0; $i&lt;$n+1; $i++) {
        for ($j=0; $j&lt;$n+1; $j++) {
            if ($tile_max &lt; $s[$i][$j]) {
                $tile_max = $s[$i][$j];
            }
        }
    }
    echo $tile_max;
?&gt;</pre></div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="660" height="160" src="https://chokomon.com/wp-content/uploads/2022/09/27-07-05-02.png" alt="" class="wp-image-6863"/></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://chokomon.com/27-prefix_sum_problems-07-05-00645/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
