We prove that for every prime $p$ there exists a (0,1)-matrix $M$ of size $t_p(n,m)\times n$, where $t_p(n,m)=O(m+\frac{m\log \frac{n}{m}}{\log \min({m,p})})$ such that every $m$ columns of $M$ are linearly independent over $\mathbb{Z}_p$, the field of integers modulo $p$ (and therefore over any field of characteristic $p$ and over the field of real numbers $\mathbb{R}$). In coding theory this matrix is a parity-check (0,1)-matrix over $\mathbb{Z}_p$ of a linear code of minimal distance m+1. Using the Hamming bound (for $p<m$) and the information theoretic argument (for $p\ge m$) it can be shown that the above bound is tight. This solves the following open problems: (1) Coin weighing problem: Suppose that $n$ coins are given among which there are at most $m$ counterfeit coins of arbitrary weights. There is a nonadaptive algorithm that finds the counterfeit coins and their weights in $t(n,m)=O((m\log n)/\log m)$ weighings. A previous result [S. S. Choi and J. H. Kim, in Proceedings of the 2008 ACM International Symposium on Theory of Computing, ACM, New York, 2008, pp. 749--758] proves the existence of a nonadaptive algorithm that solves the problem (with the same complexity) only for weights between $n^{-a}$ and $n^b$ for constants $a$ and $b$ and finds the counterfeit coins but not their weights. (2) Reconstructing graph from additive queries: Suppose that $G$ is an unknown weighted graph with $n$ vertices and at most $m$ edges. There exists a nonadaptive algorithm that finds the edges of $G$ and their weights in $O(t(n,m))$ additive queries. Previous results [S. S. Choi and J. H. Kim, in Proceedings of the 2008 ACM International Symposium on Theory of Computing, ACM, New York, 2008, pp. 749--758; N. H. Bshouty and H. Mazzawi, in Proceedings of the 20th International Conference on Algorithmic Learning Theory, Springer, Berlin, 2009, pp. 97--109] prove the existence of a nonadaptive algorithm that solves the problem only for weights between $n^{-a}$ and $n^b$ for constants $a$ and $b$ and finds the edges but not their weights. (3) Signature coding problem: Consider $n$ stations and at most $m$ of them want to send messages from $\mathbb{Z}_p$ through an adder channel, that is, a channel whose output is the sum of the messages. Then all messages can be sent (encoded and decoded) with $O(t(n,m))$ transmissions. Previous algorithms [E. Biglieri and L. Györfi, Multiple Access Channels: Theory and Practice, NATO Security through Sci. Ser. D: Inform. Commun. Security, IOS Press, Amsterdam, 2007] run with the same number of transmissions only for messages in $\{0,1\}$. Simple information theoretic arguments show that all the above bounds are tight.