Skip to content

Commit 2149a5c

Browse files
authored
Add files via upload
1 parent 67e2b89 commit 2149a5c

File tree

4 files changed

+740
-0
lines changed

4 files changed

+740
-0
lines changed

codeM/round_1/A.java

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import java.io.ByteArrayInputStream;
2+
import java.io.IOException;
3+
import java.io.InputStream;
4+
import java.io.PrintWriter;
5+
import java.math.BigInteger;
6+
import java.util.Arrays;
7+
import java.util.InputMismatchException;
8+
9+
public class A {
10+
InputStream is;
11+
PrintWriter out;
12+
String INPUT = "2 1 2\n" +
13+
"1 2\n" +
14+
"3 1";
15+
16+
private void solve() {
17+
long n = nl();
18+
long m = nl();
19+
double s1 = 0;
20+
double s2 = 0;
21+
for (long i = 1; i <= n; i++)
22+
{
23+
long a = nl();
24+
long f = nl();
25+
s1 += a * 1.0;
26+
s2 += a * (f != 0 ? 0.8 : 1.0);
27+
}
28+
double s = s2;
29+
for (long i = 1; i <= m; i++)
30+
{
31+
long b = nl();
32+
long c = nl();
33+
s = Math.min(s, s1 - (s1 < b ? 0 : c));
34+
}
35+
out.printf("%.2f\n", s);
36+
37+
38+
}
39+
40+
void run() throws Exception
41+
{
42+
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
43+
out = new PrintWriter(System.out);
44+
45+
long s = System.currentTimeMillis();
46+
solve();
47+
out.flush();
48+
tr(System.currentTimeMillis()-s+"ms");
49+
}
50+
51+
public static void main(String[] args) throws Exception { new A().run(); }
52+
53+
private byte[] inbuf = new byte[1024];
54+
public int lenbuf = 0, ptrbuf = 0;
55+
56+
private int readByte()
57+
{
58+
if(lenbuf == -1)throw new InputMismatchException();
59+
if(ptrbuf >= lenbuf){
60+
ptrbuf = 0;
61+
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
62+
if(lenbuf <= 0)return -1;
63+
}
64+
return inbuf[ptrbuf++];
65+
}
66+
67+
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
68+
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
69+
70+
private double nd() { return Double.parseDouble(ns()); }
71+
private char nc() { return (char)skip(); }
72+
73+
private String ns()
74+
{
75+
int b = skip();
76+
StringBuilder sb = new StringBuilder();
77+
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
78+
sb.appendCodePoint(b);
79+
b = readByte();
80+
}
81+
return sb.toString();
82+
}
83+
84+
private char[] ns(int n)
85+
{
86+
char[] buf = new char[n];
87+
int b = skip(), p = 0;
88+
while(p < n && !(isSpaceChar(b))){
89+
buf[p++] = (char)b;
90+
b = readByte();
91+
}
92+
return n == p ? buf : Arrays.copyOf(buf, p);
93+
}
94+
95+
private char[][] nm(int n, int m)
96+
{
97+
char[][] map = new char[n][];
98+
for(int i = 0;i < n;i++)map[i] = ns(m);
99+
return map;
100+
}
101+
102+
private int[] na(int n)
103+
{
104+
int[] a = new int[n];
105+
for(int i = 0;i < n;i++)a[i] = ni();
106+
return a;
107+
}
108+
109+
private int ni()
110+
{
111+
int num = 0, b;
112+
boolean minus = false;
113+
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
114+
if(b == '-'){
115+
minus = true;
116+
b = readByte();
117+
}
118+
119+
while(true){
120+
if(b >= '0' && b <= '9'){
121+
num = num * 10 + (b - '0');
122+
}else{
123+
return minus ? -num : num;
124+
}
125+
b = readByte();
126+
}
127+
}
128+
129+
private long nl()
130+
{
131+
long num = 0;
132+
int b;
133+
boolean minus = false;
134+
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
135+
if(b == '-'){
136+
minus = true;
137+
b = readByte();
138+
}
139+
140+
while(true){
141+
if(b >= '0' && b <= '9'){
142+
num = num * 10 + (b - '0');
143+
}else{
144+
return minus ? -num : num;
145+
}
146+
b = readByte();
147+
}
148+
}
149+
150+
private boolean oj = true;
151+
152+
//private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
153+
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
154+
}

codeM/round_1/B.java

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import java.io.ByteArrayInputStream;
2+
import java.io.IOException;
3+
import java.io.InputStream;
4+
import java.io.PrintWriter;
5+
import java.math.BigInteger;
6+
import java.util.Arrays;
7+
import java.util.InputMismatchException;
8+
9+
public class B {
10+
InputStream is;
11+
PrintWriter out;
12+
String INPUT = "2 1 2\n" +
13+
"1 2\n" +
14+
"3 1";
15+
16+
private void solve() {
17+
long n = nl();
18+
long m = nl();
19+
long k = nl();
20+
long ans = -1, max = -0x3f3f3f3f3f3f3f3fL;
21+
for (long i = 0; i < k; i++)
22+
{
23+
long a = nl(), b = nl();
24+
if (a * m + (n - m) * b >= max) {
25+
max = a * m + (n - m) * b;
26+
ans = i;
27+
}
28+
}
29+
for (long i = 0; i < k; i++)
30+
out.printf("%d%c", i == ans ? n : 0, i == k - 1 ? '\n' : ' ');
31+
32+
}
33+
34+
void run() throws Exception
35+
{
36+
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
37+
out = new PrintWriter(System.out);
38+
39+
long s = System.currentTimeMillis();
40+
solve();
41+
out.flush();
42+
tr(System.currentTimeMillis()-s+"ms");
43+
}
44+
45+
public static void main(String[] args) throws Exception { new B().run(); }
46+
47+
private byte[] inbuf = new byte[1024];
48+
public int lenbuf = 0, ptrbuf = 0;
49+
50+
private int readByte()
51+
{
52+
if(lenbuf == -1)throw new InputMismatchException();
53+
if(ptrbuf >= lenbuf){
54+
ptrbuf = 0;
55+
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
56+
if(lenbuf <= 0)return -1;
57+
}
58+
return inbuf[ptrbuf++];
59+
}
60+
61+
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
62+
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
63+
64+
private double nd() { return Double.parseDouble(ns()); }
65+
private char nc() { return (char)skip(); }
66+
67+
private String ns()
68+
{
69+
int b = skip();
70+
StringBuilder sb = new StringBuilder();
71+
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
72+
sb.appendCodePoint(b);
73+
b = readByte();
74+
}
75+
return sb.toString();
76+
}
77+
78+
private char[] ns(int n)
79+
{
80+
char[] buf = new char[n];
81+
int b = skip(), p = 0;
82+
while(p < n && !(isSpaceChar(b))){
83+
buf[p++] = (char)b;
84+
b = readByte();
85+
}
86+
return n == p ? buf : Arrays.copyOf(buf, p);
87+
}
88+
89+
private char[][] nm(int n, int m)
90+
{
91+
char[][] map = new char[n][];
92+
for(int i = 0;i < n;i++)map[i] = ns(m);
93+
return map;
94+
}
95+
96+
private int[] na(int n)
97+
{
98+
int[] a = new int[n];
99+
for(int i = 0;i < n;i++)a[i] = ni();
100+
return a;
101+
}
102+
103+
private int ni()
104+
{
105+
int num = 0, b;
106+
boolean minus = false;
107+
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
108+
if(b == '-'){
109+
minus = true;
110+
b = readByte();
111+
}
112+
113+
while(true){
114+
if(b >= '0' && b <= '9'){
115+
num = num * 10 + (b - '0');
116+
}else{
117+
return minus ? -num : num;
118+
}
119+
b = readByte();
120+
}
121+
}
122+
123+
private long nl()
124+
{
125+
long num = 0;
126+
int b;
127+
boolean minus = false;
128+
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
129+
if(b == '-'){
130+
minus = true;
131+
b = readByte();
132+
}
133+
134+
while(true){
135+
if(b >= '0' && b <= '9'){
136+
num = num * 10 + (b - '0');
137+
}else{
138+
return minus ? -num : num;
139+
}
140+
b = readByte();
141+
}
142+
}
143+
144+
private boolean oj = true;
145+
146+
//private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
147+
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
148+
}

0 commit comments

Comments
 (0)