updating delete and earn with python sol

This commit is contained in:
2026-05-14 11:45:44 -03:00
parent 189f75019b
commit 32713bd845
11 changed files with 46 additions and 4 deletions

View File

@@ -5,6 +5,8 @@
\usepackage{url}
\pagenumbering{gobble}
\usepackage{hyperref}
\usepackage{graphicx}
\input{statement/preamble.tex}
\title{ Tutorial: Análise de Dados}
\author{Leetcode 1223}

View File

@@ -34,6 +34,7 @@ Em seguida, são dados seis inteiros \(d_1, d_2, d_3, d_4, d_5, d_6\), cada um r
A saída consiste em um único inteiro representando o número total de sequências válidas de lançamentos, considerando o resultado módulo \(10^9 + 7\).
\ExemploEntrada
\begin{Exemplo}
\texttt{2} & \texttt{34}\\
\texttt{1~1~2~2~2~3} & \\

View File

@@ -43,7 +43,7 @@
},
"solutions": {
"main-ac": "ac.cpp",
"alternative-ac": [],
"alternative-ac": ["test.py"],
"wrong-answer": [],
"time-limit": [],
"time-limit-or-ac": [],

View File

@@ -5,6 +5,8 @@
\usepackage{url}
\pagenumbering{gobble}
\usepackage{hyperref}
\usepackage{graphicx}
\input{statement/preamble.tex}
\title{ Tutorial: Deletar e Ganhar}
\author{Leetcode 740}

Binary file not shown.

View File

@@ -19,6 +19,7 @@ A segunda linha contém \( n \) inteiros \( a_1, a_2, \ldots, a_n \) (\( 1 \leq
A saída deve conter um único inteiro, representando a pontuação máxima possível obtida após realizar as operações descritas.
\ExemploEntrada
\begin{Exemplo}
\texttt{3} & \texttt{8}\\
\texttt{3~4~5} & \\

View File

@@ -36,14 +36,14 @@
"run_specific_solution": "",
"generate_io_only": false,
"generate_pdf_only": false,
"cpu_count": 1,
"cpu_count": 0,
"build_pdf": true,
"pdf_format": "ds",
"io_samples": 3
},
"solutions": {
"main-ac": "ac.cpp",
"alternative-ac": [],
"alternative-ac": ["saad.py"],
"wrong-answer": ["WA.cpp"],
"time-limit": ["TLE.cpp"],
"time-limit-or-ac": [],

View File

@@ -0,0 +1,36 @@
class Solver:
def __init__(self):
self.n_ = 0
self.v_ = []
self.freq_ = []
def read_input(self) -> None:
self.n_ = int(input())
self.v_ = list(map(int, input().split()))
def process_freq(self) -> None:
self.freq_ = [0] * (max(self.v_) + 1)
for i in self.v_:
self.freq_[i] += 1
def solve(self):
self.process_freq()
dp = [0] * (max(self.v_)+1)
dp[1] = self.freq_[1]
for i in range(2, len(dp)):
dp[i] = max(dp[i-1], dp[i-2] + i * self.freq_[i])
print(dp[-1])
def main():
solver = Solver()
solver.read_input()
solver.solve()
if __name__ == "__main__":
main()