<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1102_-_Bile_2</id>
	<title>1102 - Bile 2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1102_-_Bile_2"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1102_-_Bile_2&amp;action=history"/>
	<updated>2026-06-17T08:54:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=1102_-_Bile_2&amp;diff=8990&amp;oldid=prev</id>
		<title>Corjuc Eunice: Pagină nouă: Pe o masă cad &lt;code&gt;n&lt;/code&gt; bile săltăreţe. Fiecare este lăsată să cadă liber de la o înălţime &lt;code&gt;h&lt;/code&gt;, diferită pentru fiecare bilă. Toate bilele cad simultan, cu o viteză constantă &lt;code&gt;(1m/s)&lt;/code&gt; .  În momentul în care bila &lt;code&gt;i&lt;/code&gt; atinge masa, tendinţa ei va fi să se ridice în aer până la înălţimea &lt;code&gt;h - k&lt;/code&gt;, după care aceasta cade din nou. De fiecare dată când o bilă atinge masa, aceasta va tinde să urce la o înl...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1102_-_Bile_2&amp;diff=8990&amp;oldid=prev"/>
		<updated>2024-01-04T17:09:03Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Pe o masă cad &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; bile săltăreţe. Fiecare este lăsată să cadă liber de la o înălţime &amp;lt;code&amp;gt;h&amp;lt;/code&amp;gt;, diferită pentru fiecare bilă. Toate bilele cad simultan, cu o viteză constantă &amp;lt;code&amp;gt;(1m/s)&amp;lt;/code&amp;gt; .  În momentul în care bila &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; atinge masa, tendinţa ei va fi să se ridice în aer până la înălţimea &amp;lt;code&amp;gt;h - k&amp;lt;/code&amp;gt;, după care aceasta cade din nou. De fiecare dată când o bilă atinge masa, aceasta va tinde să urce la o înl...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Pe o masă cad &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; bile săltăreţe. Fiecare este lăsată să cadă liber de la o înălţime &amp;lt;code&amp;gt;h&amp;lt;/code&amp;gt;, diferită pentru fiecare bilă. Toate bilele cad simultan, cu o viteză constantă &amp;lt;code&amp;gt;(1m/s)&amp;lt;/code&amp;gt; .&lt;br /&gt;
&lt;br /&gt;
În momentul în care bila &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; atinge masa, tendinţa ei va fi să se ridice în aer până la înălţimea &amp;lt;code&amp;gt;h - k&amp;lt;/code&amp;gt;, după care aceasta cade din nou. De fiecare dată când o bilă atinge masa, aceasta va tinde să urce la o înlăţime cu &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; mai mică decât cea la care a urcat anterior. Dupa multe sărituri, bilele pot obosi şi nu vor mai sări. Când bilele sar în sus, vor urca tot cu aceeaşi viteza constantă.&lt;br /&gt;
&lt;br /&gt;
Dându-se &amp;lt;code&amp;gt;h&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; pentru fiecare dintre cele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; bile, să se răspundă la &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; întrebări de forma: La ce înălţime faţă de masă se va afla bila &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; în momentul &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; ?&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;input.txt&amp;lt;/code&amp;gt; conţine pe prima linie 2 numere naturale &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt;. Pe următoarele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii se află o pereche de numere, &amp;lt;code&amp;gt;h&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt; . Următoarele &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; linii vor conţine &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; numere naturale &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;t&amp;lt;/code&amp;gt; cu semnificaţiile de mai sus.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
În fişierul de ieşire &amp;lt;code&amp;gt;output.txt&amp;lt;/code&amp;gt; se vor afişa &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; linii, răspunsurile la cele &amp;lt;code&amp;gt;m&amp;lt;/code&amp;gt; întrebări.&lt;br /&gt;
&lt;br /&gt;
= Restricţii =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n, m ≤ 100.000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exemplul 1 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
2 3&lt;br /&gt;
&lt;br /&gt;
5 1&lt;br /&gt;
&lt;br /&gt;
8 2&lt;br /&gt;
&lt;br /&gt;
1 4&lt;br /&gt;
&lt;br /&gt;
1 7&lt;br /&gt;
&lt;br /&gt;
2 16&lt;br /&gt;
&lt;br /&gt;
output.txt:&lt;br /&gt;
&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
2&lt;br /&gt;
&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
Explicație:&lt;br /&gt;
&lt;br /&gt;
Bila &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; cade de la înălţimea &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt; timp de &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt; secunde apoi se opreşte la înălţimea &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Bila &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; cade de la înălţimea &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt; şi atinge pământul, iar în cele &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; secunde rămase ajunge la înălţimea &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Bila &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; cade de la înălţimea &amp;lt;code&amp;gt;8&amp;lt;/code&amp;gt;, atinge pământul şi apoi ajunge la noua sa înălţime maximă, &amp;lt;code&amp;gt;6&amp;lt;/code&amp;gt;, în &amp;lt;code&amp;gt;14&amp;lt;/code&amp;gt; secunde. în cele &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; secunde rămase, bila apucă să coboare la înălţimea &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Exemplul 2 ==&lt;br /&gt;
input.txt:&lt;br /&gt;
&lt;br /&gt;
999999999999 3&lt;br /&gt;
&lt;br /&gt;
5 1&lt;br /&gt;
&lt;br /&gt;
8 2&lt;br /&gt;
&lt;br /&gt;
1 4&lt;br /&gt;
&lt;br /&gt;
1 7&lt;br /&gt;
&lt;br /&gt;
2 16&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
Constraints not met!&lt;br /&gt;
&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python3&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
def verify_constraints(n, m):&lt;br /&gt;
    return 1 &amp;lt;= n &amp;lt;= 100000 and 1 &amp;lt;= m &amp;lt;= 100000&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    with open(&amp;quot;input.txt&amp;quot;, &amp;quot;r&amp;quot;) as fin, open(&amp;quot;output.txt&amp;quot;, &amp;quot;w&amp;quot;) as fout:&lt;br /&gt;
        N = 100005&lt;br /&gt;
        h = [0] * N&lt;br /&gt;
        k = [0] * N&lt;br /&gt;
&lt;br /&gt;
        n, m = map(int, fin.readline().split())&lt;br /&gt;
&lt;br /&gt;
        if not verify_constraints(n, m):&lt;br /&gt;
            print(&amp;quot;Constraints not met!&amp;quot;)&lt;br /&gt;
            return&lt;br /&gt;
&lt;br /&gt;
        for i in range(1, n + 1):&lt;br /&gt;
            h[i], k[i] = map(int, fin.readline().split())&lt;br /&gt;
&lt;br /&gt;
        for _ in range(m):&lt;br /&gt;
            x, t = map(int, fin.readline().split())&lt;br /&gt;
&lt;br /&gt;
            crt = h[x]&lt;br /&gt;
            height = h[x]&lt;br /&gt;
&lt;br /&gt;
            if t &amp;lt;= h[x]:&lt;br /&gt;
                fout.write(f&amp;quot;{h[x] - t}\n&amp;quot;)&lt;br /&gt;
                continue&lt;br /&gt;
&lt;br /&gt;
            t -= h[x]&lt;br /&gt;
            height = 0&lt;br /&gt;
            crt -= k[x]&lt;br /&gt;
&lt;br /&gt;
            while t and crt:&lt;br /&gt;
                if t &amp;lt;= crt:&lt;br /&gt;
                    height += t&lt;br /&gt;
                    t = 0&lt;br /&gt;
                else:&lt;br /&gt;
                    t -= crt&lt;br /&gt;
                    height = crt&lt;br /&gt;
&lt;br /&gt;
                if not t:&lt;br /&gt;
                    break&lt;br /&gt;
&lt;br /&gt;
                if t &amp;lt;= crt:&lt;br /&gt;
                    height -= t&lt;br /&gt;
                    t = 0&lt;br /&gt;
                else:&lt;br /&gt;
                    t -= crt&lt;br /&gt;
                    height = 0&lt;br /&gt;
&lt;br /&gt;
                crt = max(0, crt - k[x])&lt;br /&gt;
&lt;br /&gt;
            fout.write(f&amp;quot;{height}\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Corjuc Eunice</name></author>
	</entry>
</feed>