QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#686630#9528. New Energy VehiclerefWA 0ms3676kbC++201.4kb2024-10-29 14:50:112024-10-29 14:50:11

Judging History

This is the latest submission verdict.

  • [2024-10-29 14:50:11]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3676kb
  • [2024-10-29 14:50:11]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
typedef pair<int,int> PII;
const int N=1e5+10;
const int inf=1e18;
int a[N];
PII xt[N];
int res,ans;
int n,m;
bool check(int mid)
{
    if(res>=mid)
    {
        return true;
    }
    int res1=res;
    for(int i=m;i>=1;i--)
    {
        if(xt[i].first>mid)
        {
            continue;
        }
        if(xt[i].first-xt[i-1].first>a[xt[i].second])
        {
            res1+=a[xt[i].second];
        }
        else
        {
            res1+=(xt[i].first-xt[i-1].first);
        }
    }
    if(res1>=mid)
    {
        return true;
    }
    return false;
}
void solve()
{
    ans=0;
    res=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        res+=a[i];
    }
    xt[0].first=0;
    for(int i=1;i<=m;i++)
    {
        cin>>xt[i].first>>xt[i].second;
    }
    sort(xt+1,xt+1+m);
    int l=1,r=inf;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid))
        {
            ans=max(mid,ans);
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }
    }
    cout<<ans<<endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int t;
	while(cin>>t)
	{
        while(t--)
        {   
            solve();
        }
    }
} 

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3676kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
10
11
1999999998
2000000000

result:

wrong answer 3rd lines differ - expected: '4', found: '10'