Last active
January 27, 2020 16:42
-
-
Save Chgtaxihe/51c3fb94efd178b1f0fe2e408548777e to your computer and use it in GitHub Desktop.
Codeforces 1260 #Codeforces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 1e5 + 100; | |
void solve() { | |
int n, c, sum; | |
cin >> n; | |
for(int i=0; i<n; i++){ | |
cin >> c >> sum; | |
ll d = sum / c, e = sum % c; | |
cout << d * d * (c - e) + (d + 1) * (d + 1) * e << '\n'; | |
} | |
} | |
signed main() { | |
Android; | |
solve(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
class IoTool: # a tool for input redirection | |
DEBUG = 0 | |
def _reader_dbg(): | |
with open('./input.txt', 'r') as f: | |
lines = f.readlines() | |
for l in lines: yield l.strip() | |
def _reader_oj(): | |
return iter(sys.stdin.read().split('\n')) | |
reader = _reader_dbg() if DEBUG else _reader_oj() | |
def read(): return next(IoTool.reader) | |
input = IoTool.read | |
def main(): | |
a, b = map(int, input().split()) | |
if (a + b) % 3 != 0: | |
print('NO') | |
elif min(a, b) * 2 < max(a, b): | |
print('NO') | |
else: | |
print('YES') | |
if __name__ == "__main__": | |
n = int(input()) | |
for _ in range(n): | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd(a, b): | |
return a if b == 0 else gcd(b, a%b) | |
def main(): | |
r, b, k = map(int, input().split()) | |
g = gcd(r, b) | |
r, b = min(r, b), max(r, b) # r <= b | |
if g + (k-1) * r < b: | |
print('REBEL') | |
else: | |
print('OBEY') | |
if __name__ == "__main__": | |
n = int(input()) | |
for _ in range(n): | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0; i<n; i++) | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const ll inf = 0x3f3f3f3f3f3f3f3f; | |
const int maxn = 2e5 + 100; | |
int m, n, k, t; | |
int a[maxn], l[maxn], r[maxn], d[maxn]; | |
int cost(int tar){ | |
vector<pair<int, int> > section; | |
F(i, k){ | |
if(d[i] > tar) section.push_back({l[i], r[i]}); | |
} | |
sort(section.begin(), section.end()); | |
int lastr = 0, cst = 0; | |
for(pair<int, int> pii:section){ | |
if(pii.first <= lastr){ | |
cst += max(0, pii.second - lastr); | |
lastr = max(lastr, pii.second); | |
}else{ | |
cst += pii.second - pii.first + 1; | |
lastr = pii.second; | |
} | |
} | |
// cout << "a: " << tar << " cst " << 2 * cst + n + 1 << endl; | |
return 2 * cst + n + 1; | |
} | |
void solve() { | |
cin >> m >> n >> k >> t; | |
F(i, m) cin >> a[i]; | |
F(i, k) cin >> l[i] >> r[i] >> d[i]; | |
sort(a, a + m, greater<int>()); | |
int le = 0, re = m, mid; | |
while(le < re){ | |
mid = (le + re) >> 1; | |
if(cost(a[mid]) <= t) | |
le = mid + 1; | |
else | |
re = mid; | |
} | |
cout << le << endl; | |
} | |
signed main() { | |
Android; | |
solve(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment