Skip to content

Commit

Permalink
Create aprizenoonecanwin
Browse files Browse the repository at this point in the history
* OK: C++
* NO: JavaScript (Node.js)
  • Loading branch information
EntityPlantt committed Aug 13, 2022
1 parent 0784d93 commit cd95eb0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions aprizenoonecanwin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
size_t n, x, now = 0, last = 0;
cin >> n >> x;
size_t arr[n];
for (size_t i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
for (size_t i = 0; i < n; i++) {
last = now;
now = arr[i];
if (last + now > x) {
cout << max(i, size_t(1));
return 0;
}
}
cout << n;
return 0;
}
23 changes: 23 additions & 0 deletions aprizenoonecanwin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// GitHub: EntityPlantt/Kattis
// Not working
var n, x, last = 0, now = 0;
require("readline").createInterface({input: process.stdin}).on("line", arr => {
arr = arr.split(" ").map(elm => parseInt(elm));
if (n == undefined) {
n = arr[0];
x = arr[1];
}
else {
arr.sort();
for (var i = 0; i < n; i++) {
last = now;
now = arr[i];
if (last + now > x) {
console.log(Math.max(i, 1));
process.exit();
}
}
console.log(n);
process.exit();
}
});

0 comments on commit cd95eb0

Please sign in to comment.