#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5;
int n, m;
int a[MAXN];
long long prefix[MAXN];
bool compare(int x, int y)
{
return a[x]>a[y];
}
long long sum(int l, int r)
{
if (l==0)
return prefix[r];
return prefix[r]-prefix[l-1];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i=0; i<n; i++)
cin >> a[i];
for (int i=0; i<m; i++)
{
int x, y;
cin >> x >> y;
}
int sorted[n];
for (int i=0; i<n; i++)
sorted[i]=i;
sort(sorted, sorted+n, compare);
int possible[n]={false};
possible[sorted[0]]=true;
set<int> larger;
vector<int> wait;
wait.push_back(sorted[0]);
prefix[0]=a[0];
for (int i=1; i<=n; i++)
prefix[i]=prefix[i-1]+a[i];
for (int i=1; i<n; i++)
{
int x=sorted[i];
if (a[x]!=a[sorted[i-1]])
while (!wait.empty())
{
larger.insert(wait.back());
wait.pop_back();
}
int l=-1, r=n;
auto it=larger.lower_bound(x);
if (it!=larger.end())
r=*it;
if (it!=larger.begin())
{
it--;
l=*it;
}
if (l==-1 && r==n)
possible[x]=true;
if (l!=-1 && possible[l] && sum(l+1, r-1)>=a[l])
possible[x]=true;
if (r!=n && possible[r] && sum(l+1, r-1)>=a[r])
possible[x]=true;
wait.push_back(x);
//larger.insert(x);
}
for (int i=0; i<n; i++)
cout << possible[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
81 ms |
13860 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
108 ms |
13820 KB |
Output is correct |
3 |
Incorrect |
118 ms |
13904 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
80 ms |
12832 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |