QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665306 | #6443. Windblume Festival | SYease | WA | 124ms | 3644kb | C++17 | 1.8kb | 2024-10-22 11:12:25 | 2024-10-22 11:12:25 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<set>
#include<cmath>
#include<queue>
#define int long long
#define endl '\n'
#define F first
#define S second
#define sz size()
#define B begin()
#define D end()
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int N=1e6+10;
const int mod=1e9+7;
struct Nod{
int b;
int e;
}dian[N];
int a[N];
void solve()
{
int n;
cin>>n;
int mxi=1,mni=1;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int mx=a[1],mn=a[1];
for(int i=1;i<=n;i++){
if(mx<a[i]) {
if(mn>mx){
mn=mx;
mni=mxi;
}
mx=a[i];
mxi=i;
continue;
}
if(mn>a[i]){
mn=a[i];
mni=i;
}
}
//cout<<mni<<endl;
int ans=mx;
if(n==1){
cout<<ans<<endl;
return;
}
for(int i=1;i<=n;i++){
if(i==mxi||i==mni) continue;
if(a[i]<=0){
//cout<<ans<<' '<<a[i]<<endl;
ans-=a[i];
}else{//cout<<mn<<' '<<a[i]<<endl;
mn-=a[i];
}
}
ans-=mn;
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int tc=1;
cin>>tc;
while(tc--)
{
solve();
}
return 0;
}
int ksm(int m,int k,int mod)
{
int ans=1;
int t=m;
while(k)
{
if(k&1) ans=ans*t%mod;
t=t*t%mod;
k>>=1;
}
return ans;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int exgcd(int a,int b,__int128& x,__int128& y)
{
if(b==0){
x=1,y=0;
return a;//返回值为gcd(a,b)
}
int res=exgcd(b,a%b,x,y);//迭代到最底层
int t=x;
x=y;
y=t-(a/b)*y;
//完成实现时的x1=y2,y1=x2-(a/b)*y2
//由于是从最深层实现的,故直接用公式向上层传递即可
return res;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
5 4 1 -3 2 -4 11 91 66 73 71 32 83 72 79 84 33 93 12 91 66 73 71 32 83 72 79 84 33 33 93 13 91 66 73 71 32 83 72 79 84 33 33 33 93 1 0
output:
10 713 746 779 0
result:
ok 5 number(s): "10 713 746 779 0"
Test #2:
score: 0
Accepted
time: 99ms
memory: 3580kb
input:
1000000 1 2 1 -2 1 1 1 -1 1 2 1 1 1 2 1 -2 1 -2 1 2 1 1 1 1 1 2 1 2 1 2 1 -2 1 -2 1 0 1 2 1 1 1 -1 1 0 1 -2 1 0 1 1 1 1 1 -2 1 -2 1 2 1 1 1 2 1 1 1 1 1 0 1 2 1 0 1 -1 1 -1 1 -2 1 -2 1 0 1 -2 1 0 1 1 1 -1 1 2 1 0 1 -2 1 -2 1 0 1 1 1 -1 1 -2 1 -1 1 0 1 -1 1 -1 1 -1 1 -1 1 1 1 2 1 0 1 0 1 -2 1 2 1 2 1 ...
output:
2 -2 1 -1 2 1 2 -2 -2 2 1 1 2 2 2 -2 -2 0 2 1 -1 0 -2 0 1 1 -2 -2 2 1 2 1 1 0 2 0 -1 -1 -2 -2 0 -2 0 1 -1 2 0 -2 -2 0 1 -1 -2 -1 0 -1 -1 -1 -1 1 2 0 0 -2 2 2 -1 2 -2 -1 -2 -1 -2 2 -1 -1 0 -2 0 0 0 1 1 2 1 -1 0 -2 1 2 1 1 0 1 2 -2 -1 -1 0 -2 2 2 1 0 -1 0 -1 0 1 -2 2 1 -2 -2 0 -1 1 -1 2 -2 2 1 1 2 0 2...
result:
ok 1000000 numbers
Test #3:
score: 0
Accepted
time: 124ms
memory: 3624kb
input:
1000000 1 -182188011 1 -889401027 1 -379434063 1 -731536137 1 632523155 1 837208235 1 192807861 1 -162604370 1 963735146 1 736725265 1 -70315400 1 659481275 1 217883785 1 -396219883 1 653358757 1 -489133046 1 412498823 1 -210628961 1 -137310415 1 849916587 1 -50143945 1 -509463528 1 105005776 1 7382...
output:
-182188011 -889401027 -379434063 -731536137 632523155 837208235 192807861 -162604370 963735146 736725265 -70315400 659481275 217883785 -396219883 653358757 -489133046 412498823 -210628961 -137310415 849916587 -50143945 -509463528 105005776 738262345 352827098 391146170 108054338 601933024 -705538291...
result:
ok 1000000 numbers
Test #4:
score: -100
Wrong Answer
time: 83ms
memory: 3620kb
input:
666685 1 0 2 2 -1 1 2 1 2 1 -1 2 -2 2 1 0 2 -1 -2 2 2 -1 2 0 1 2 2 -1 1 1 2 1 1 1 1 2 0 2 2 1 0 2 0 2 2 -1 2 1 1 1 -1 1 -2 1 2 2 -1 0 2 -2 1 2 -2 -2 2 0 -1 1 -2 1 2 1 2 2 -1 -1 1 1 1 -2 1 2 2 -2 1 2 2 1 2 0 -2 1 -1 1 0 1 2 1 -2 2 2 0 1 -1 2 0 0 2 2 -2 2 -2 0 1 -2 1 1 2 2 0 1 -2 1 -1 2 1 -1 2 1 -2 2 ...
output:
0 3 2 2 -1 4 0 1 3 1 3 1 1 1 2 1 2 3 1 -1 -2 2 1 3 2 1 -2 2 2 1 1 -2 2 3 1 2 -1 0 2 -2 2 -1 0 4 2 -2 1 2 -2 -1 2 3 2 -2 3 4 2 2 -2 1 2 3 3 2 2 2 1 -2 2 1 1 0 2 -1 2 0 2 2 1 2 4 1 1 4 -2 -1 3 1 1 1 1 0 -2 2 1 2 2 1 2 -2 0 2 2 1 2 -1 0 -2 2 -1 2 1 3 1 1 -1 0 1 2 2 -1 1 -1 2 0 1 -1 -1 -2 1 0 2 1 -2 2 2...
result:
wrong answer 13th numbers differ - expected: '0', found: '1'