<?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=1096_-_Expresie_8</id>
	<title>1096 - Expresie 8 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=1096_-_Expresie_8"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1096_-_Expresie_8&amp;action=history"/>
	<updated>2026-05-01T06:37:59Z</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=1096_-_Expresie_8&amp;diff=9636&amp;oldid=prev</id>
		<title>Raul: Pagină nouă: Costel are de rezolvat o temă grea la matematică: având la dispoziţie &lt;code&gt;N&lt;/code&gt; numere naturale nenule trebuie să aşeze între acestea &lt;code&gt;2&lt;/code&gt; operaţii de înmulţire şi &lt;code&gt;N-3&lt;/code&gt; operaţii de adunare, astfel încât rezultatul calculelor să fie cel mai mare posibil. Nu este permisă modificarea ordinii numerelor date.  De exemplu, dacă &lt;code&gt;N=5&lt;/code&gt; şi numerele sunt &lt;code&gt;4&lt;/code&gt;, &lt;code&gt;7&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;5&lt;/code&gt;, &lt;code&gt;3&lt;/code...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=1096_-_Expresie_8&amp;diff=9636&amp;oldid=prev"/>
		<updated>2024-02-13T14:42:46Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: Costel are de rezolvat o temă grea la matematică: având la dispoziţie &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale nenule trebuie să aşeze între acestea &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; operaţii de înmulţire şi &amp;lt;code&amp;gt;N-3&amp;lt;/code&amp;gt; operaţii de adunare, astfel încât rezultatul calculelor să fie cel mai mare posibil. Nu este permisă modificarea ordinii numerelor date.  De exemplu, dacă &amp;lt;code&amp;gt;N=5&amp;lt;/code&amp;gt; şi numerele sunt &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;7&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Costel are de rezolvat o temă grea la matematică: având la dispoziţie &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale nenule trebuie să aşeze între acestea &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; operaţii de înmulţire şi &amp;lt;code&amp;gt;N-3&amp;lt;/code&amp;gt; operaţii de adunare, astfel încât rezultatul calculelor să fie cel mai mare posibil. Nu este permisă modificarea ordinii numerelor date.&lt;br /&gt;
&lt;br /&gt;
De exemplu, dacă &amp;lt;code&amp;gt;N=5&amp;lt;/code&amp;gt; şi numerele sunt &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;7&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;5&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;,  operaţiile pot fi aşezate &amp;lt;code&amp;gt;4+7*1+5*3&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;4*7*1+5+3&amp;lt;/code&amp;gt;, e.t.c&lt;br /&gt;
&lt;br /&gt;
= Cerinţă =&lt;br /&gt;
Scrieţi un program care să aşeze două operaţii de înmulţire şi &amp;lt;code&amp;gt;N-3&amp;lt;/code&amp;gt; operaţii de adunare între cele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; valori date astfel încât valoarea expresiei obţinute să fie maximă.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fișierul de intrare &amp;lt;code&amp;gt;expresie8.in&amp;lt;/code&amp;gt; are următoarea structură:&lt;br /&gt;
&lt;br /&gt;
* Pe prima linie se află un număr natural &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt;, reprezentând numărul elementelor date.&lt;br /&gt;
* Pe următoarele linii se află cele &amp;lt;code&amp;gt;N&amp;lt;/code&amp;gt; numere naturale date, fiecare pe câte o linie.&lt;br /&gt;
&lt;br /&gt;
= Date de ieșire =&lt;br /&gt;
Fișierul de ieșire &amp;lt;code&amp;gt;expresie8.out&amp;lt;/code&amp;gt; va conține pe prima linie valoarea maximă obţinută prin evaluarea expresiei.&lt;br /&gt;
&lt;br /&gt;
= Restricții și precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;4 &amp;lt;= N &amp;lt;= 1000&amp;lt;/code&amp;gt;&lt;br /&gt;
* Numerele date sunt numere naturale între &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; şi &amp;lt;code&amp;gt;10000&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Exemplu: =&lt;br /&gt;
&amp;lt;code&amp;gt;expresie8.in&amp;lt;/code&amp;gt;&lt;br /&gt;
 5&lt;br /&gt;
 4&lt;br /&gt;
 7&lt;br /&gt;
 1&lt;br /&gt;
 5&lt;br /&gt;
 3&lt;br /&gt;
&amp;lt;code&amp;gt;expresie8.out&amp;lt;/code&amp;gt;&lt;br /&gt;
 44&lt;br /&gt;
&lt;br /&gt;
= Explicație =&lt;br /&gt;
Valoarea maximă se obţine prin aşezarea operaţiilor sub forma: &amp;lt;code&amp;gt;4 * 7 + 1 + 5*3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Încărcare soluție ==&lt;br /&gt;
&lt;br /&gt;
=== Lipește codul aici ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;expresie8.in&amp;quot;, &amp;quot;r&amp;quot;) as fin, open(&amp;quot;expresie8.out&amp;quot;, &amp;quot;w&amp;quot;) as fout:&lt;br /&gt;
    n = int(fin.readline())&lt;br /&gt;
    v = list(map(int, fin.readline().split()))&lt;br /&gt;
    &lt;br /&gt;
    s = 0&lt;br /&gt;
    Max = 0&lt;br /&gt;
    for i in range(1, n+1):&lt;br /&gt;
        s += v[i]&lt;br /&gt;
    &lt;br /&gt;
    for i in range(1, n-1):&lt;br /&gt;
        cc = s - v[i] - v[i+1] - v[i+2] + (v[i] * v[i+1] * v[i+2])&lt;br /&gt;
        if cc &amp;gt; Max:&lt;br /&gt;
            Max = cc&lt;br /&gt;
    &lt;br /&gt;
    for i in range(1, n-2):&lt;br /&gt;
        for j in range(i+2, n):&lt;br /&gt;
            cc = s - v[i] - v[i+1] - v[j] - v[j+1] + (v[i] * v[i+1]) + (v[j] * v[j+1])&lt;br /&gt;
            if cc &amp;gt; Max:&lt;br /&gt;
                Max = cc&lt;br /&gt;
                &lt;br /&gt;
    fout.write(str(Max) + &amp;quot;\n&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Raul</name></author>
	</entry>
</feed>