813A - The Contest - CodeForces Solution


implementation *1100

Please click on ads to support us..

Python Code:

n=int(input())
a=list(map(int,input().split()))
m=int(input())
end1=[0]
start1=[0]
for i in range(m):
    start,end=map(int,input().split())
    start1.append(start)
    end1.append(end)


for i in range(len(end1)):
    if end1[i]>=sum(a) and start1[i]<=sum(a):
        print(sum(a))
    if start1[i]>sum(a) and sum(a)>end1[i-1]:
        print(start1[i])
if sum(a)>end1[-1]:
    print(-1)

	   	 	  		  	 	  			    		   	

C++ Code:

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define KholiD freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define KK ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ld long double
using namespace std ;
/**

“So verily, with the hardship, there is a relief.” [Quran 94:5]

**/

ll p , l , r ;
void solve(){
    ll n ;
    cin >> n ;
    while ( n -- )
        cin >> l , p += l ;
    cin >> n ;
    while ( n -- && p > r )
        cin >> l >> r ;
    cout << ( p > r ? -1 : max ( p , l ) ) ;
}

int main(){KK
    ll t = 1 ;
    ///cin >> t ;
    while ( t -- )
        solve () ;
}


Comments

Submit
0 Comments
More Questions

1515C - Phoenix and Towers
998A - Balloons
1734F - Zeros and Ones
1144B - Parity Alternated Deletions
92B - Binary Number
1144C - Two Shuffled Sequences
1154B - Make Them Equal
1272B - Snow Walking Robot
522B - Photo to Remember
608B - Hamming Distance Sum
1408F - Two Different
274B - Zero Tree
1726H - Mainak and the Bleeding Polygon
722A - Broken Clock
129B - Students and Shoelaces
697B - Barnicle
903D - Almost Difference
1443B - Saving the City
1215C - Swap Letters
1251C - Minimize The Integer
1494B - Berland Crossword
295A - Greg and Array
1433E - Two Round Dances
1612D - X-Magic Pair
41B - Martian Dollar
906C - Party
774F - Pens And Days Of Week
598B - Queries on a String
1303B - National Project
1303D - Fill The Bag