<?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=0317_-_SumMax</id>
	<title>0317 - SumMax - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0317_-_SumMax"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0317_-_SumMax&amp;action=history"/>
	<updated>2026-05-01T04:07:46Z</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=0317_-_SumMax&amp;diff=7723&amp;oldid=prev</id>
		<title>Gabii: am adaugat explicatia</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0317_-_SumMax&amp;diff=7723&amp;oldid=prev"/>
		<updated>2023-12-09T22:18:11Z</updated>

		<summary type="html">&lt;p&gt;am adaugat explicatia&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:18, 9 December 2023&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l22&quot;&gt;Line 22:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 22:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;summaxOUT.txt&amp;lt;/code&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;code&amp;gt;summaxOUT.txt&amp;lt;/code&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  57&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  57&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Explicație ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;code&amp;gt;57=16+11+17+13&amp;lt;/code&amp;gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Exemplul 2 =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Exemplul 2 =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Gabii</name></author>
	</entry>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=0317_-_SumMax&amp;diff=7642&amp;oldid=prev</id>
		<title>Gabii: Pagină nouă: = Cerinţa = Se dă o matrice pătratică cu &lt;code&gt;n&lt;/code&gt; lini şi &lt;code&gt;n&lt;/code&gt; coloane şi elemente numere naturale distincte. Determinaţi cea mai mare sumă a &lt;code&gt;n&lt;/code&gt; elemente din matrice, cu proprietatea că oricare două elemente se află pe linii şi coloane distincte.  = Date de intrare = Fişierul de intrare &lt;code&gt;summaxIN.txt&lt;/code&gt; conţine pe prima linie numărul &lt;code&gt;n&lt;/code&gt;, iar pe următoarele &lt;code&gt;n&lt;/code&gt; linii câte &lt;code&gt;n&lt;/code&gt; numere natural...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0317_-_SumMax&amp;diff=7642&amp;oldid=prev"/>
		<updated>2023-12-04T18:01:16Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: = Cerinţa = Se dă o matrice pătratică cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; lini şi &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; coloane şi elemente numere naturale distincte. Determinaţi cea mai mare sumă a &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; elemente din matrice, cu proprietatea că oricare două elemente se află pe linii şi coloane distincte.  = Date de intrare = Fişierul de intrare &amp;lt;code&amp;gt;summaxIN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe următoarele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii câte &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere natural...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Cerinţa =&lt;br /&gt;
Se dă o matrice pătratică cu &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; lini şi &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; coloane şi elemente numere naturale distincte. Determinaţi cea mai mare sumă a &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; elemente din matrice, cu proprietatea că oricare două elemente se află pe linii şi coloane distincte.&lt;br /&gt;
&lt;br /&gt;
= Date de intrare =&lt;br /&gt;
Fişierul de intrare &amp;lt;code&amp;gt;summaxIN.txt&amp;lt;/code&amp;gt; conţine pe prima linie numărul &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt;, iar pe următoarele &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; linii câte &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; numere naturale, separate prin spaţii, reprezentând elementele matricei.&lt;br /&gt;
&lt;br /&gt;
= Date de ieşire =&lt;br /&gt;
Fişierul de ieşire &amp;lt;code&amp;gt;summaxOUT.txt&amp;lt;/code&amp;gt; va conţine pe prima linie numărul &amp;lt;code&amp;gt;S&amp;lt;/code&amp;gt;, reprezentând suma maximă determinată. În cazul în care restricțiile nu sunt îndeplinite, se va afișa mesajul &amp;quot;Nu corespunde restricțiilor&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= Restricţii şi precizări =&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;1 ≤ n ≤ 10&amp;lt;/code&amp;gt;&lt;br /&gt;
* elementele matricei vor avea cel mult &amp;lt;code&amp;gt;4&amp;lt;/code&amp;gt; cifre&lt;br /&gt;
&lt;br /&gt;
= Exemplul 1 =&lt;br /&gt;
&amp;lt;code&amp;gt;summaxIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 4&lt;br /&gt;
 12 16 5 4&lt;br /&gt;
 11 14 6 7&lt;br /&gt;
 8 2 3 17&lt;br /&gt;
 10 9 13 15&lt;br /&gt;
&amp;lt;code&amp;gt;summaxOUT.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 57&lt;br /&gt;
&lt;br /&gt;
= Exemplul 2 =&lt;br /&gt;
&amp;lt;code&amp;gt;summaxIN.txt&amp;lt;/code&amp;gt;&lt;br /&gt;
 100000&lt;br /&gt;
consola&lt;br /&gt;
 Nu corespunde restricțiilor&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 citeste_matrice(file_path):&lt;br /&gt;
    with open(file_path, &amp;#039;r&amp;#039;, encoding=&amp;#039;utf-8&amp;#039;) as file:&lt;br /&gt;
        n = int(file.readline().strip())&lt;br /&gt;
        matrice = [list(map(int, file.readline().split())) for _ in range(n)]&lt;br /&gt;
    return n, matrice&lt;br /&gt;
&lt;br /&gt;
def scrie_rezultat(file_path, rezultat):&lt;br /&gt;
    with open(file_path, &amp;#039;w&amp;#039;, encoding=&amp;#039;utf-8&amp;#039;) as file:&lt;br /&gt;
        file.write(str(rezultat))&lt;br /&gt;
&lt;br /&gt;
def verifica_restrictii(n, matrice):&lt;br /&gt;
    if not (1 &amp;lt;= n &amp;lt;= 10):&lt;br /&gt;
        return False&lt;br /&gt;
&lt;br /&gt;
    for linie in matrice:&lt;br /&gt;
        for element in linie:&lt;br /&gt;
            if not (0 &amp;lt;= element &amp;lt;= 9999):&lt;br /&gt;
                return False&lt;br /&gt;
&lt;br /&gt;
    return True&lt;br /&gt;
&lt;br /&gt;
def gaseste_suma_maxima(n, matrice):&lt;br /&gt;
    elemente_sortate = sorted([(matrice[i][j], i, j) for i in range(n) for j in range(n)], reverse=True)&lt;br /&gt;
&lt;br /&gt;
    linii_selectate = set()&lt;br /&gt;
    coloane_selectate = set()&lt;br /&gt;
&lt;br /&gt;
    suma_maxima = 0&lt;br /&gt;
&lt;br /&gt;
    for element, i, j in elemente_sortate:&lt;br /&gt;
        if i not in linii_selectate and j not in coloane_selectate:&lt;br /&gt;
            suma_maxima += element&lt;br /&gt;
            linii_selectate.add(i)&lt;br /&gt;
            coloane_selectate.add(j)&lt;br /&gt;
&lt;br /&gt;
    return suma_maxima&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    fisier_intrare = &amp;quot;summaxIN.txt&amp;quot;&lt;br /&gt;
    fisier_iesire = &amp;quot;summaxOUT.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    n, matrice = citeste_matrice(fisier_intrare)&lt;br /&gt;
&lt;br /&gt;
    if verifica_restrictii(n, matrice):&lt;br /&gt;
        rezultat = gaseste_suma_maxima(n, matrice)&lt;br /&gt;
        if rezultat &amp;gt; 0:&lt;br /&gt;
            scrie_rezultat(fisier_iesire, rezultat)&lt;br /&gt;
        else:&lt;br /&gt;
            scrie_rezultat( &amp;quot;Nu corespunde restrictiilor&amp;quot;.encode(&amp;#039;utf-8&amp;#039;))&lt;br /&gt;
    else:&lt;br /&gt;
        scrie_rezultat(fisier_iesire, &amp;quot;Nu corespunde restricțiilor&amp;quot;.encode(&amp;#039;utf-8&amp;#039;).decode(&amp;#039;utf-8&amp;#039;))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gabii</name></author>
	</entry>
</feed>