Class Homework
Practice
2.3 (6 votes)
Ad Hoc
Algorithms
Approved
Dynamic programming
Medium
Open
Two dimensional
Problem
55% Success 1491 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Ramesh and Suresh were in the same class and got home work from their mathematics teacher. The Homework consists of N strings and each string consists of only digits. The task which they need to perform is that they need to divide the string into 4 integers such that their sum is maximum.
Note:
Each integer should be ≤ 1012 and should not contain any leading zeroes.
As we know that Suresh and Ramesh are weak in mathematics and also they don't want to be punished. So, they need your help for finding the answer.
INPUT:
First line contains an integer N denoting the number of strings. Next N lines contain N strings each consists of digits only.
OUTPUT:
For each test case, Print the required answer if exists. Print "unlucky" otherwise.
CONSTRAINTS:
- 1 ≤ N ≤ 104
- 1 ≤ size of each string ≤ 20
SUBTASKS:
- subtask 1 : 1 ≤ N ≤ 102 : ( 50 pts )
- subtask 2 : 1 ≤ N ≤ 104 : ( 50 pts )
Submissions
Please login to view your submissions
Similar Problems
Points:30
16 votes
Tags:
ApprovedBasic ProgrammingImplementationMediumOpenRecursionTwo dimensional
Points:30
5 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMathMediumOpen
Points:30
3 votes
Tags:
MediumTwo dimensional
Editorial