原题链接


http://codeforces.com/contest/813/problem/A


解题思想



代码


#include<iostream>
using namespace std;

int main()
{
    int m,n,i,x,t=0,l,r=0;
    cin>>n;
    while(n--)
    {
        cin>>x;
        t+=x;
    }
    cin>>m;
    while(m--&&t>r)cin>>l>>r;
    if(t>r) cout<<-1;
    else cout<<max(t,l);
    return 0;
}