Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):


#include <bits/stdc++.h>



#define go ios::sync_with_stdio(0);cin.tie(0)

#define srv(v) sort(v.begin(), v.end())

#define yes cout<<"YES"<<endl

#define no cout<<"NO"<<endl

#define vi vector<int>

#define vll vector<ll>

#define vl vector<l>



typedef long l;

typedef long long  ll;

typedef long long int lli;

typedef unsigned long long ull;



constexpr auto PI = 3.14159265358979323846;



using namespace std;



unsigned long long factorial(ll n) {

if (n == 0 || n == 1) {

return 1;

} else {

return n * factorial(n - 1);

}

}



bool isPrime(ll n) {

if (n == 1)

return false;

if (n == 2)

return true;

for (int i = 2; i <= sqrt(n); i++) {

if (n % i == 0)

return false;

}

return true;

}



ll smallestDiv(ll n) {

for (int i = 2; i <= sqrt(n); i++) {

if (n % i == 0) {

return i;

}

}

return n;

}



lli binaryToDecimal(string binary) {

lli decimal = 0;

int power = 0;



for (int i = binary.length() - 1; i >= 0; i--) {

if (binary[i] == '1') {

decimal += pow(2, power);

}

power++;

}

return decimal;

}



bool binarySearch(vector<ll>& a, ll target) {

ll left = 0, right = a.size() - 1;

while (left <= right) {

ll mid = left + (right - left) / 2;

if (a[mid] == target) {

return true;

} else if (a[mid] > target) {

right = mid - 1;

} else left = mid + 1;

}

return false;

}



int main() {

go;

int t; cin >> t;

while(t--) {

int n;

cin >> n;

vi v(n);

for(auto &e: v) cin >> e;







for(int i = 0; i < n - 1; i++){

if(v[i] < v[i + 1]) {

v[i + 1] -= v[i];

v[i] = 0;

}

}



bool f = true;

for(int i = 0;i < n - 1; i++){

if(v[i] > v[i + 1]){

f = false;

break;

}

}



if(f) yes;

else no;

}





}

Submission (verdict: Wrong answer on test 2):


#include <bits/stdc++.h>



#define go ios::sync_with_stdio(0);cin.tie(0)

#define srv(v) sort(v.begin(), v.end())

#define yes cout<<"YES"<<endl

#define no cout<<"NO"<<endl

#define vi vector<int>

#define vll vector<ll>

#define vl vector<l>



typedef long l;

typedef long long  ll;

typedef long long int lli;

typedef unsigned long long ull;



constexpr auto PI = 3.14159265358979323846;



using namespace std;



unsigned long long factorial(ll n) {

if (n == 0 || n == 1) {

return 1;

} else {

return n * factorial(n - 1);

}

}



bool isPrime(ll n) {

if (n == 1)

return false;

if (n == 2)

return true;

for (int i = 2; i <= sqrt(n); i++) {

if (n % i == 0)

return false;

}

return true;

}



ll smallestDiv(ll n) {

for (int i = 2; i <= sqrt(n); i++) {

if (n % i == 0) {

return i;

}

}

return n;

}



lli binaryToDecimal(string binary) {

lli decimal = 0;

int power = 0;



for (int i = binary.length() - 1; i >= 0; i--) {

if (binary[i] == '1') {

decimal += pow(2, power);

}

power++;

}

return decimal;

}



bool binarySearch(vector<ll>& a, ll target) {

ll left = 0, right = a.size() - 1;

while (left <= right) {

ll mid = left + (right - left) / 2;

if (a[mid] == target) {

return true;

} else if (a[mid] > target) {

right = mid - 1;

} else left = mid + 1;

}

return false;

}



int main() {

go;

int t; cin >> t;

while(t--) {

int n;

cin >> n;

vi v(n);

for(auto &e: v) cin >> e;



for(int i = 0; i < n - 2; i++){

if(v[i] < v[i + 1]) {

v[i + 1] -= v[i];

v[i] = 0;

}

}



bool f = true;

for(int i = 0;i < n - 1; i++){

if(v[i] > v[i + 1]){

f = false;

break;

}

}



if(f) yes;

else no;

}





}