# DBLDROP - Editorial

**URL:** <https://discuss.codechef.com/t/dbldrop-editorial/126197>\
**Category:** editorial\
**Tags:** editorial, start266\
**Created:** [November 25, 2026, 4:30pm UTC](https://discuss.codechef.com/t/dbldrop-editorial/126197 "2026-11-25T16:30:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iceknight1093](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@iceknight1093](https://discuss.codechef.com/u/iceknight1093)\
**Post date:** [November 25, 2026, 4:30pm UTC](https://discuss.codechef.com/t/dbldrop-editorial/126197/1 "2026-11-25T16:30:50Z")

</div>

# PROBLEM LINK:

[Practice](https://www.codechef.com/problems/DBLDROP)  
[Contest: Division 1](https://www.codechef.com/START266A/problems/DBLDROP)  
[Contest: Division 2](https://www.codechef.com/START266B/problems/DBLDROP)  
[Contest: Division 3](https://www.codechef.com/START266C/problems/DBLDROP)  
[Contest: Division 4](https://www.codechef.com/START266D/problems/DBLDROP)

_ **Author:** _ [raysh07](https://www.codechef.com/users/raysh07)  
_ **Tester:** _ [iceknight1093](https://www.codechef.com/users/iceknight1093)  
_ **Editorialist:** _ [iceknight1093](https://www.codechef.com/users/iceknight1093)

# DIFFICULTY:

TBD

# PREREQUISITES:

None

# PROBLEM:

You’re given an array A.  
You may choose at most one index i and replace A\_i by 2\cdot A\_i.

The score of the array is \text{sum}(A) - \max(A).  
Find the maximum possible score after the operation.

# EXPLANATION:

The constraints are low enough that the obvious \mathcal{O}(N^2) brute force will pass.  
However, there is a better solution.

Let S = \text{sum}(A) and M = \max(A).  
If we don’t perform the operation, the score is just S - M.

Otherwise, suppose we double A\_i.  
Then,

- The sum increases by A\_i, so it becomes S + A\_i.
- The new maximum is \max(M, 2A\_i), since A\_i is the only element that changed.

So, the score is S + A\_i - \max(M, 2A\_i).

There are only N choices of i, so just try all of them and take the best result.  
This gives a linear time solution.

# TIME COMPLEXITY:

\mathcal{O}(N) per testcase.

# CODE:

> **Editorialist's code (PyPy3)**
>
> ```python
> for _ in range(int(input())):
> n = int(input())
> a = list(map(int, input().split()))
>     
> s, m = sum(a), max(a)
> ans = s - m
> for i in range(n):
> ans = max(ans, s + a[i] - max(m, 2*a[i]))
> print(ans)
> 
> ```
